vue3 tinymce4实现复制word文档内容保留原格式

封装组件
<template>
    <div class="tinymce-editor">
      <textarea :id="id" v-model="Value"></textarea>
   </div>
</template>

<script>
import '../../../public/tinymce/tinymce.min.js'
window.tinymce.baseURL = '/tinymce'
window.tinymce.suffix = '.min'

export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      id: 'vue-tinymce-' + Date.now(),
      Value: this.value,
      flag: true
    }
  },
  mounted () {
    tinymce.init({
      selector: `#${this.id}`,
      language: 'zh_CN',
      height: 500,
      theme: 'modern',
      plugins: 'powerpaste print preview fullpage searchreplace autolink directionality code visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools media contextmenu colorpicker textpattern help',
      toolbar: 'undo redo | formatselect | bold italic strikethrough forecolor backcolor fontsizeselect | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat fullscreen  preview save print | link code',
      fontsize_formats: '8px 10px 12px 13px 14px 16px 18px 24px 36px 48px',
      //黏贴功能
	    powerpaste_word_import: 'propmt',// 参数可以是propmt, merge, clear,效果自行切换对比
      powerpaste_html_import: 'propmt',// propmt, merge, clear
      powerpaste_allow_local_images: true,
      paste_data_images: true,
      //上传图片功能
      //automatic_uploads: true,//自动上传	
	    image_advtab: true,//开启图片上传的高级选项功能
      image_title: true, // 是否开启图片标题设置的选择,这里设置否
      //images_upload_url: '',//上传图片地址
      images_upload_handler: function (blobInfo, success, failure) {
   	    const base64Img = "data:image/jpeg;base64," + blobInfo.base64();
   	    success(base64Img);
      },
      init_instance_callback: editor => {
        editor.on('input change undo redo execCommand', () => {
          this.flag = false;
          this.$emit('input', editor.getContent())
        })
      },
      images_dataimg_filter: function(img) {
    	  return img.hasAttribute('internal-blob');
      },
      paste_preprocess: function(plugin, args) {}  
	 });
  },
  beforeDestroy: function(){
    if (tinymce.get(this.id)) {
      tinymce.get(this.id).destroy();
    }
  },
  watch: {
    value(val){
      if(this.flag){
        this.$nextTick(() => tinymce.get(this.id).setContent(val))
      }
      this.flag = true;
    }
  }
}
</script>

引用组件
<template>
    <div class="container__r-content">
        <tinymce-editor ref="editor" v-model="msg"></tinymce-editor>
    </div>
</template>
import TinymceEditor from 'components/Tinymce.vue'
export default {
    components: {
        TinymceEditor
    },
    data() {
        return {
            msg:'',
        }
    }
 }
</script>

其中会用到tinymce powerpaste插件:下载地址

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值