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值

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

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算