1、Vue中在使用Vue CLI开发中默认无法使用UEditorjavascript
其中UEditor中也存在很多错误,再引用过程当中。php
可是UEditor相对仍是比较好用的一个富文本编辑器。html
vue-ueditor-wrap说明vue
Vue + UEditor + v-model 双向绑定。之因此有这个 repo
的缘由是:
一、UEditor 依然是国内使用频率极高的所见即所得编辑器而 Vue 又有着普遍的使用,因此将二者结合使用,是不少 Vue 项目开发者的切实需求。
二、目前没有发现知足这种需求,而使用又很方便的 repo
、有的可能也只是简单的暴露一个 UEditor
的实例,仍然须要开发者手动去调用 getContent
,setContent
,而经过 v-model
绑定数据也是不少人期待的方式。java
官方地址:https://github.com/HaoChuan9421/vue-ueditor-wrapgit
2、使用步骤github
1.安装vue-editor-wrapvue-cli
npm i vue-ueditor-wrap
2.下载处理后的UEditor,下载地址npm
解压,重命名文件夹为UEditor,放入public文件夹下(若是是旧项目对应static文件夹)。app
3.引用组件、注册组件
import VueUeditorWrap from "vue-ueditor-wrap"; // ES6 Module export default { name: "app", components: { VueUeditorWrap }, data() { return { msg: '<h2><img src="http://img.baidu.com/hi/jx2/j_0003.gif"/>Vue + UEditor + v-model双向绑定!+!$#</h2>', myConfig: { UEDITOR_HOME_URL: "/UEditor/", serverUrl: "" } }; }, methods: { showOne() { alert(this.msg); } } };
4.v-model绑定数据
<template> <div id="app"> <vue-ueditor-wrap v-model="msg" :config="myConfig"></vue-ueditor-wrap> <p> <el-button type="primary" @click="showOne();">获取编辑器内容</el-button> </p> </div> </template>
3、使用说明
1.根据项目需求修改从组件处修改配置
<vue-ueditor-wrap v-model="msg" :config="myConfig"></vue-ueditor-wrap>
data () { return { msg: '<h2><img src="http://img.baidu.com/hi/jx2/j_0003.gif"/>Vue + UEditor + v-model双向绑定</h2>', myConfig: { // 编辑器不自动被内容撑高 autoHeightEnabled: false, // 初始容器高度 initialFrameHeight: 240, // 初始容器宽度 initialFrameWidth: '100%', // 上传文件接口(这个地址是我为了方便各位体验文件上传功能搭建的临时接口,请勿在生产环境使用!!!) serverUrl: 'http://35.201.165.105:8000/controller.php', // UEditor 资源文件的存放路径,若是你使用的是 vue-cli 生成的项目,一般不须要设置该选项,vue-ueditor-wrap 会自动处理常见的状况,若是须要特殊配置,参考下方的常见问题2 UEDITOR_HOME_URL: '/static/UEditor/' } } }
2.也能够全局修改vue-ueditor-wrap.vue 源码
4、最终显示结果:
更多: