element-ui + el-dialog + Vue.component 注册的tinymce富文本控件 第二次及以后打开dialog出现问题解决方法
Vue.component('my-tinymce', { props: ['value'], data(){ return{ flag:true } }, watch:{ value(val){ //console.log(val); if(this.flag){ tinymce.activeEditor.setContent(val); } this.flag = true; } }, mounted: function(){ const self = this; tinymce.init({ target: this.$el.children[0], //theme: 'modern',//inlite mobile modern language: "zh_CN", menubar: false, branding: false, valid_elements: "p[style],span[style],ul,ol,li,strong/b,em,h1,h2,h3,h4,h5,h6", valid_style: { "*":"color,font_size,text-align,line-height" }, plugins: [ //配置插件:可自己随意选择,但如果是上传本地图片image和imagetools是必要的 'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker', 'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking', 'save table contextmenu directionality emoticons template paste imagetools textcolor' ], /*表情 emoticons*/ toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | preview media fullpage | forecolor backcolor | code fullscreen | formatselect | table', // images_upload_url:basePath()+'/platform/res/upload/img', // images_upload_base_path:'', // images_upload_credentials:true, setup: function(editor) { editor.on('input undo redo execCommand', function(e) { self.flag = false; self.$emit('input', editor.getContent()); }); }, images_upload_handler: function (blobInfo, success, failure) { //console.log(blobInfo); //console.log(success); //console.log(failure); let formData = new FormData(); formData.append('file', blobInfo.blob(), blobInfo.filename()); $.ajax({ url : basePath()+'/platform/res/upload/img', type : "POST", data : formData, cache : false, async : true, contentType : false, // 这两句需要添加上,否则会跳转页面 processData : false, dataType : "json", success : function(obj) { if(obj.code == 0){ console.log(obj.data.location); success(obj.data.location); }else{ failure('上传出错了'); } }, error : function () { failure('上传出错了,图片限制上传最大为2M'); } }); } }); }, updated(){ }, created(){ }, destroyed(){ }, template: '<div><textarea style="height:300px" v-model="value"></textarea></div>' });
自定控件 添加属性 v-if="dialogVisible" 或者使用element-ui较新的话可以在在el-dialog 标签上添加 :destroy-on-close="true" 关闭时dialog销毁dialog内的控件
<el-dialog title="" :visible.sync="dialogVisible" :append-to-body="true"> <my-tinymce v-model="data" v-if="dialogVisible"></my-tinymce> </el-dialog>
这样设置是为了关闭dialog时销毁my-editor控件,不销毁的话会出现问题的
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端