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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • rst 网络_RST报文

    rst 网络_RST报文????现实很近又很冷,梦想很远却很温暖​欢迎关注CSDN:https://blog.csdn.net/ndrg55?spm=1011.2124.3001.5343&type=blog语雀:https://www.yuque.com/u12089348以下内容来源:https://mp.weixin.qq.com/s/Fr6o6gRiIUIspV9-jR9snw作者:小白debug注:内容有所改动一、什么是RST我们都知道TCP正常情况下断开连接是用四次挥手,那是正常时候的

    2022年9月28日
    4
  • python中astype 存在空值_python-DataFrame.astype()错误参数

    python中astype 存在空值_python-DataFrame.astype()错误参数使用列的字典时,astype引发ValueError.我试图将大DF中的稀疏列的类型转换(从float到int).我的问题是NaN值.即使将errors参数设置为’ignore’,使用列的字典时也不会忽略它们.这是一个玩具示例:t=pd.DataFrame([[1.01,2],[3.01,10],[np.NaN,20]])t.astype({0:int},errors=’ignore’)V…

    2022年5月25日
    79
  • Jenkins安装_Noam Jenkins

    Jenkins安装_Noam Jenkins前言jenkins的环境搭建方法有很多,本篇使用docker快速搭建一个jenkins环境。环境准备:mac/Linuxdockerdocker拉去jenkins镜像先下载jenkins镜

    2022年7月30日
    10
  • 什么是跨域及怎么解决跨域问题?[通俗易懂]

    什么是跨域及怎么解决跨域问题?[通俗易懂]什么是跨域?这篇博文解释的挺清楚,我直接引用https://blog.csdn.net/lambert310/article/details/51683775跨域,指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器施加的安全限制。所谓同源是指,域名,协议,端口均相同,只要有一个不同,就是跨域。不明白没关系,举个栗子:http://www.123.com/i…

    2022年4月29日
    43
  • linux 系统进行make menuconfig的时候出错

    linux 系统进行make menuconfig的时候出错错误信息:(ps:当前系统:Linuxlabpc4.13.0-36-generic#40~16.04.1-UbuntuSMPFriFeb1623:25:58UTC2018x86_64x86_64x86_64GNU/Linux)HOSTCCscripts/kconfig/mconf.oInfileincludedfromscripts/kc…

    2022年5月25日
    35
  • c语言小游戏百度云资源,c语言小游戏合集

    c语言小游戏百度云资源,c语言小游戏合集这是c语言小游戏合集下载,这是我用c语言写的程序,我在大三上学期的劳动成果展示。我的其他资源都是免费的,是对于c语言初学者的帮助比较大的,其中有数据结构,window编程。我也在学c语言,每当我写完一个程序,我都会免费发上来。软件介绍c语言小游戏合集是本人在网上搜集的C语言编写的经典小游戏的源码集合,有志于C游戏编程学习的朋友可以选用参考。软件说明100个比较经典的C语言代码分享给大家,我都加了注…

    2022年5月18日
    37

发表回复

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

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