vue使用wangeditor4.0版本,并实现编辑器内容双向绑定

本文介绍了如何在Vue项目中使用wangeditor4.0,包括下载安装、封装组件Editor以及实现编辑器内容与Vue数据的双向绑定。通过监听组件内外变化,确保编辑器内容与父组件参数同步。
摘要由CSDN通过智能技术生成

下载安装

npm i wangeditor --save

封装组件Editor

  1. 新建Vue组件Editor
  2. 初始化编辑器组件
    <template lang="html">
        <div id="editor">
        </div>
    </template>
    
    <script>
        import E from 'wangeditor'
        export default {
            name: 'Editor',
            data() {
                return {
                    editor: ''
                }
            },
            mounted() {
                const editor = new E("#editor");
                this.editor = editor; // 保存创建的实例
                editor.create();
            }
        }
    </script>
    

     

  3. 接收父组件传入的富文本内容参数
    props: {
        content: {
            type: String,
            default: ''
        }
    },
  4. 监听父组件传入参数的变化,并初始化至编辑器中
    watch: {
        content() {
            this.editor.txt.html(this.content); 
        }
    }
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值