LewisRoc 2021-04-27 10:36 采纳率: 60%
浏览 295
已采纳

弹框中的ckeditor5富文本编辑器怎么在关闭弹窗时清空刷新内容啊

我做的是vue的后台管理项目,在修改的弹框中有一个富文本编辑器里边能回显当前项得文本和图片内容从而进行修改,我用的别人封装的组件,每次关闭当前弹框再点击其他弹框时富文本编辑器中显示的还是第一个弹框的内容除非手动刷新一下浏览器,请教各位大神怎么解决啊,下边是我编辑器组件的代码和父组件关闭弹框的监听事件

<template>
  <div class="editBigCon generateReport" style="height:300px">
    <div class="toolbarContainer">   
      <div id="toolbar-container"></div>
    </div>
    <div id="editor-container" style="height:200px">
      <div id="editor"></div>
    </div>
  </div>
</template>

<script>
 
  import DecoupledEditor from '@ckeditor/ckeditor5-build-decoupled-document'
  import '@ckeditor/ckeditor5-build-decoupled-document/build/translations/zh-cn.js'

  var that;

  export default {
    // props: ['reviewReport'],
    name: "",
    mixins:"",
    components: {},
    data () {
      return {
        editor:null,//编辑器实例
        editorHeight:0,//报告文档的高度
        template:"",
        reviewReport: "",
      }
    },
    created(){

    },
    computed: {},
    mounted(){
      that = this;
      that.setDefaultCssResize();
      that.$nextTick(function(){
      that.initCKEditor();
      });
    },
    methods: {
      setDefaultCssResize(){
        that.$nextTick(function(){
          that.editorHeight = document.body.clientHeight - 163;
        });
      },
      getItem(){
        return document.querySelector('#editor').innerHTML;
      },
      // 定义关闭弹框后清空编辑器内容的方法
      clearImg() {
        this.reviewReport= ''
        this.$forceUpdate()
        // CKEditor.instances.generateReport.setData(' ')
      },
      initCKEditor() {
       DecoupledEditor.create(document.querySelector('#editor'), {
          language: 'zh-cn',
          toolbar: ['heading','|','bold', 'italic', 'Underline', 'fontSize', 'highlight', '|', 'numberedList', 'bulletedList', '|', 'alignment:left', 'alignment:right', 'alignment:center', 'alignment:justify', '|','Indent','Outdent','|','imageUpload','Link','insertTable','|','redo', 'undo', ],//撤销,//重做
          ckfinder: {
          uploadUrl:'https://factory.sunspots.tech/factory/fileupload/uploadImgFordapeng'//后端处理上传逻辑返回json数据,包括uploaded(选项true/false)和url两个字段
          }
        }).then(editor => {
          
          const toolbarContainer = document.querySelector('#toolbar-container');
          toolbarContainer.appendChild(editor.ui.view.toolbar.element);
                setTimeout(() => {
          editor.setData(this.reviewReport);
          this.$forceUpdate()
      },500)
          // 上传图片获取的数据
          this.editor = editor;

        }).catch(error => {
          // console.error(error);
        });
      },
      
    },
  }
</script>

上边是封装的编辑器子组件下边是父组件中代码

     

      // 更新确定按钮
      editInformation() {
        this.editDialogVisible = false
        // let usrls = typeof(this.imageUrl[0]) == 'undefined'?'':this.imageUrl[0];
        // console.log(usrls)
        let param = {
          newsId: this.editList.newsId,
          content: this.$refs.generateReports.getItem(),
          title: this.editList.title,
          type: this.editList.type
        }
        // debugger
        this.$http.post('/news/update_one', param).then((res) => {
        this.$message.success('更新成功')
        this.getNewsList()
        console.log(res);
        })
      },
      // 更新对话框取消按钮关闭事件
      editNo() {
        // 调用子组件清空编辑器内容方法
        this.$refs.generateReports.clearImg()
        // 关闭弹窗
        this.editDialogVisible = false
        this.getNewsList()
      },
      // 监听更新对话框的关闭事件
      upDateDialogClosed() {
        // location. reload()
        // this.$router.go(0)
        this.$refs.generateReports.clearImg()
        this.$refs.upDateFormList.resetFields()
        this.$refs.generateReports.reviewReport = ''
        this.getNewsList()
        
      },
  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2021-04-27 10:49
    关注

    1.手动清除数据destory里(推荐使用这个)

    2.给组件加个随机的key值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效