vue项目引入Ueditor

查看文档

UEditor官方github链接
https://github.com/fex-team/ueditor
github地址

下载UEditor官方文件

选择zip文件下载并解压
npm i 
全局安装grunt
npm install grunt-cli -g
npm install grunt --save-dev
终端输入
grunt default

得到文件dist

将文件里面的utf8-php改名editor,放入public static下的editor文件中

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
修改ueditor.config.js里面的上图那行

vue页面处理

html部分
在这里插入图片描述
js部分

import '../../public/static/editor/ueditor.config.js'
import '../../public/static/editor/ueditor.all.js'
import '../../public/static/editor/lang/zh-cn/zh-cn.js'
import '../../public/static/editor/ueditor.parse.js'

在这里插入图片描述
css部分

<style  scoped>
@import '../../public/static/editor/themes/default/css/ueditor.min.css';
</style>

运行

在这里插入图片描述

1. 下载 UEditor 下载地址:http://ueditor.baidu.com/website/download.html 2. 在 Vue 项目中创建 UEditor 组件 在 src/components 目录下创建 UEditor.vue 文件,然后在里面写入以下代码: <template> <div :id="editorId"></div> </template> <script> export default { props: { value: { type: String, default: '', }, config: { type: Object, default: () => ({}), }, }, data() { return { editorId: `editor_${Date.now()}_${Math.random().toString().substr(2)}`, }; }, mounted() { // 异步加载 UEditor.js const id = this.editorId; const config = this.config; const value = this.value; const _self = this; const ueditorScript = document.createElement('script'); ueditorScript.setAttribute('src', 'http://cdn.staticfile.org/ueditor/1.4.3.3/ueditor.all.js'); document.body.appendChild(ueditorScript); ueditorScript.onload = function () { const editor = window.UE.getEditor(id, config); editor.ready(function () { editor.setContent(value); }); editor.addListener('contentChange', function () { _self.$emit('input', editor.getContent()); }); }; }, beforeDestroy() { // 销毁 UEditor 实例 window.UE.getEditor(this.editorId).destroy(); }, }; </script> 3. 在 Vue 项目中使用 UEditor 组件 在需要使用 UEditor 的页面中引入 UEditor 组件,然后在 template 中使用即可。 <template> <div class="ueditor-container"> <ueditor v-model="content" :config="config" /> </div> </template> <script> import UEditor from '@/components/UEditor.vue'; export default { components: { UEditor, }, data() { return { content: '', config: { initialFrameHeight: 500, autoHeightEnabled: false, autoFloatEnabled: false, toolbars: [ ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'strikethrough', 'fontfamily', 'fontsize', 'forecolor', 'backcolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'insertorderedlist', 'insertunorderedlist', 'blockquote', 'link', 'unlink', 'inserttable', 'deletetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'splittocells', 'removeformat', 'cleardoc', 'preview'], ], }, }; }, }; </script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值