vue 富文本编辑框_基于vue的富文本编辑器

vue 富文本编辑框_基于vue的富文本编辑器1、下载插件npmiwangeditor–save插件官网地址:https://www.wangeditor.com/2、封装富文本组件<templatelang=”html”><divclass=”editor”><!–<divref=”toolbar”class=”toolbar”></div>–><divref=”editor”class=”text”></div

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

1、下载插件

npm i wangeditor –save
插件官网地址:https://www.wangeditor.com/

2、封装富文本组件

<template lang="html">
  <div class="editor">
    <!-- <div ref="toolbar" class="toolbar"></div> -->
    <div ref="editor" class="text"></div>
  </div>
</template>

<script>
  import E from 'wangeditor'
  export default {
    name: 'editoritem',
    data() {
      return {
        // uploadPath,
        editor: null,
        info_: null
      }
    },
    model: {
      prop: 'value',
      event: 'change'
    },
    props: {
      value: {
        type: String,
        default: ''
      },
      isClear: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      isClear(val) {
        // 触发清除文本域内容
        if (val) {
          this.editor.txt.clear()
          this.info_ = null
        }
      },
      value: function(value) {
        if (value !== this.editor.txt.html()) {
          this.editor.txt.html(this.value)
        }
      }
      //value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值
    },
    mounted() {
      this.seteditor()
    },
    beforeDestroy() {
      // 调用销毁 API 对当前编辑器实例进行销毁
      this.editor.destroy()
      this.editor = null
    },
    methods: {
      seteditor() {
        this.editor = new E( this.$refs.editor)
        // this.editor.customConfig = this.editor.customConfig ? this.editor.customConfig : this.editor.config;
        // 配置 server 上传图片接口地址
        // this.editor.config.uploadImgServer = '/upload-img'
        this.editor.config.onchange = (html) => {
          this.info_ = html // 绑定当前值
          this.$emit('change', this.info_) // 将内容同步到父组件中
        }


        // 自定义 alert
        this.editor.config.customAlert = function (s, t) {
          switch (t) {
            case 'success':
              this.$Message.success(s)
              break
            case 'info':
              this.$Message.info(s)
              break
            case 'warning':
              this.$Message.warning(s)
              break
            case 'error':
              this.$Message.error(s)
              break
            default:
              this.$Message.info(s)
              break
          }
        }
        // 配置全屏功能按钮是否展示
       this.editor.config.showFullScreen = false

        // 创建富文本编辑器
        this.editor.create()
        this.editor.txt.html(this.value) // 重新设置编辑器内容
      }
    }
  }
</script>
<style lang="scss">
  .editor {
    width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 0;
  }
  .toolbar {
    border: 1px solid #ccc;
  }
  .text {
    border: 1px solid #ccc;
     min-height: 200px;
    .w-e-text-container{
      height: 200px!important;
    }
    .w-e-text{
      min-height: 200px;
    }
  }
</style>

3、使用组件

<template>
  <div>
    <wangEnduit
      v-model="Content"
      :isClear="isClear"
      @change="change"
      :value="Content"
    />
  </div>
</template>

<script>
export default {
  components: {
    wangEnduit: () => import('@/components/wangEnduit/index'),
  },
  data(){
    return{
      Content:"",
      isClear: false,
    }
  },
  methods:{
      change(val) {
      console.log('val',val)
    },
  }
}
</script>

<style>

</style>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/184117.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • jni 头文件_java.io.file

    jni 头文件_java.io.file1,cmd切换到应用工程目录下如示例中的D:\zxy\IDCardQualityLib2,执行javah命令,红色部分为sdk平台android.jar路径,蓝色部分为生成的jni类名 D:\zxy\IDCardQualityLib>javah-classpath bin/classes;d:\tool\adt-bundle-windows-x86-20131030\adt-b

    2022年9月2日
    4
  • Petshop4学习

    Petshop4学习Petshop4的研究分析:http://blog.csdn.net/sjklove/archive/2006/11/10/1377405.aspx1.项目概述与架构分析微软刚推出了基于ASP.NET2.0下的PetShop4,该版本有了一个全新的用户界面。是研究ASP.NET2.0的好范例啊,大家都知道,一直以来,在.NET和Java之间争论不休,到底使用哪个平台开发的企业级应用性…

    2022年10月17日
    0
  • 前端语音信号处理

    前端语音信号处理1、语音活动检测语音活动检测(VoiceActivityDetection,VAD)用于检测出语音信号的起始位置,分离出语音段和非语音(静音或噪声)段。VAD算法大致分为三类:基于阈值的VAD、基于分类器的VAD和基于模型的VAD。基于阈值的VAD是通过提取时域(短时能量、短时过零率等)或频域(MFCC、谱熵等)特征,通过合理的设置门限,达到区分语音和非语音的目的;基于分类…

    2022年5月25日
    54
  • matlab在极坐标中绘图y=sin(6x)_极坐标中θ范围怎么求

    matlab在极坐标中绘图y=sin(6x)_极坐标中θ范围怎么求在极坐标中绘图TryThisExampleTryThisExampleTryThisExampleTryThisExampleTryThisExampleTryThi

    2022年8月5日
    0
  • Bitmap.MakeTransparent 方法

    Bitmap.MakeTransparent 方法使默认的透明颜色对此Bitmap透明。重载列表使默认的透明颜色对此Bitmap对象透明。[Visual Basic]OverloadsPublicSubMakeTransparent()[C#]publicvoidMakeTransparent();[C++]public:voidMakeTransparent();[JScript]publicfunctionM

    2022年7月21日
    11
  • edge开启ie兼容模式_edge ie兼容模式

    edge开启ie兼容模式_edge ie兼容模式Edge,IE浏览器兼容模式设置

    2022年9月8日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号