Vue嵌入百度富文本编辑器UEditor

8 篇文章 0 订阅
7 篇文章 1 订阅
本文档介绍了如何在Vue项目中引入并配置已编译的1.5.0版UEditor,将编译后的UEditor放入public/plugins/ueditor目录下,并修改ueditor.config.js的根路径。接着在组件中创建UEditor.vue,初始化UEditor,设置全屏等配置,并讨论了后续可能的代码优化,如参数化配置、多编辑器共存及双向数据绑定等实现方式。
摘要由CSDN通过智能技术生成

引入项目的是编译后的1.5.0版本的UEditor,我另一篇文章写的如何编译1.5.0版本的UEditor
编译后,把dist文件里面文件放到项目的public/plugins/ueditor
在这里插入图片描述
相关自定义配置看官方文档就行了,为了快速把项目搭建好,我就改了ueditor.config.js的根路径
在这里插入图片描述
注意路径最前面也要加上/

之后在component文件夹下创建一个UEditor.vue文件,在里面初始化UEditor。

<template>
  <div id="ueditor"></div>
</template>

<script>
import '../../../public/plugins/UEditor/ueditor.config'
import '../../../public/plugins/UEditor/ueditor.all'
import '../../../public/plugins/UEditor/lang/zh-cn/zh-cn'
import '../../../public/plugins/UEditor/themes/default/css/ueditor.css'

export default {
  name: "UEditor",
  data() {
    return {
      UEditor: null
    }
  },
  mounted() {
    this.initUEditor()
  },
  beforeDestroy() {
    if (this.UEditor && this.UEditor.destroy) this.UEditor.destroy()
  },
  methods: {
    initUEditor() {
      let config = {
        fullscreen: true
      }
      // eslint-disable-next-line no-undef
      this.UEditor = UE.getEditor('ueditor', config)
      this.UEditor.addEventListener('ready', () => {
        console.log('UEditor is Ready')
      })
    }
  }
}
</script>

<style>

</style>

后面要对代码进行优化,比如config设置为可传参数、id也是(为了兼容多编辑器共存的问题)
或者通过setContent和事件总线bus,来实现编辑器里面值得绑定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值