vue引用vue-ueditor-wrap组件,一个页面要多次渲染UEditor编辑器时,v-mode绑定失效,v-mode值改变编辑器内容不改变解决方式

**

vue引用vue-ueditor-wrap组件,一个页面要多次渲染UEditor编辑器时,v-mode绑定失效解决方式

**
博主ueditor编辑器使用情况是在一个el-dialog弹出框里,每次打开都要渲染不同的数据,但是这时候给绑定的v-mode赋值无法改变编辑器里的内容,只有初次赋值有效。直接改变v-mode绑定的值是不行的。
首先是在页面引入编辑器组件在这里插入图片描述
在这里插入图片描述
然后配置一些编辑器的基本参数
在这里插入图片描述
在引入编辑器的时候注意加入一个 @ready="方法名"方法如图二,用来获取到编辑器对象的key,在这里插入图片描述
然后给弹出框添加一个关闭事件@close=‘方法名’,每次关闭的时候手动获取到编辑器对象并将其值变为空,在这里插入图片描述
在这里插入图片描述
使用UE.getEditor()方法获取到对象,其中第一个参数是之前获取到的key,第二个是编辑器配置,在使用setContent()方法将其值变为空。同时也要对v-mode绑定的值赋值。
每次打开弹出框加载编辑器的时候同理
在这里插入图片描述
这里需要做个判断当编辑器的key不为空的时候使用上述方法获取到编辑器对象并进行赋值,同时也要对v-mode绑定的值赋值。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
为了封装vue-ueditor-wrap,可以按照以下步骤进行操作: 1.安装vue-ueditor-wrapueditor ```shell npm install vue-ueditor-wrap ueditor --save ``` 2.在main.js中引入ueditor ```javascript import Vue from 'vue' import App from './App.vue' import UEditor from 'vue-ueditor-wrap' import 'ueditor/ueditor.config.js' import 'ueditor/ueditor.all.min.js' import 'ueditor/lang/zh-cn/zh-cn.js' Vue.component('u-editor', UEditor) new Vue({ el: '#app', render: h => h(App) }) ``` 3.在组件中使用vue-ueditor-wrap ```vue <template> <div> <u-editor v-model="content"></u-editor> </div> </template> <script> export default { data() { return { content: '' } } } </script> ``` 4.封装vue-ueditor-wrap一个独立的组件 ```vue <template> <div> <u-editor v-model="content"></u-editor> </div> </template> <script> import UEditor from 'vue-ueditor-wrap' import 'ueditor/ueditor.config.js' import 'ueditor/ueditor.all.min.js' import 'ueditor/lang/zh-cn/zh-cn.js' export default { name: 'VueUeditorWrap', components: { UEditor }, props: { value: { type: String, default: '' } }, data() { return { content: this.value } }, watch: { value(val) { this.content = val }, content(val) { this.$emit('input', val) } } } </script> ``` 5.在其他组件中使用封装好的vue-ueditor-wrap组件 ```vue <template> <div> <vue-ueditor-wrap v-model="content"></vue-ueditor-wrap> </div> </template> <script> import VueUeditorWrap from './VueUeditorWrap.vue' export default { components: { VueUeditorWrap }, data() { return { content: '' } } } </script> ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值