<template>
  <div class="UE">
    <div :id="id" type="text/plain"></div>
  </div>
</template>
<script>
  import '@@@/UE/ueditor.config.js'
  import '@@@/UE/ueditor.all.min.js'
  import '@@@/UE/lang/zh-cn/zh-cn.js'
  import '@@@/UE/ueditor.parse.min.js'

  export default {
    name: 'UE',
    props: {
      defaultMsg: {
        type: String
      },
      config: {
        type: Object
      },
      id: {
        type: String
      }
    },
    data () {
      return {
        editor: null
      }
    },
    watch: {
      defaultMsg () {
        this.editor.setContent(this.defaultMsg)
      }
    },
    mounted () {
      const _this = this
      this.editor = window.UE.getEditor(this.id, this.config) // 初始化UE
      this.editor.addListener('ready', function () {
        _this.editor.setContent(_this.defaultMsg) // 确保UE加载完成后，放入内容。
      })
    },
    methods: {
      getUEContent () { // 获取内容方法
        return this.editor.getContent()
      }
    },
    destroyed () {
      this.editor.destroy()
    }
  }
</script>
<style scoped>
  .UE {
    line-height: 20px;
  }
</style>
