在vue中创建多个ueditor实例
简介
在vue中创建多个ueditor实例,我使用neditor,其实就是把ueditor样式美化了下,其他和ueditor几乎一样
截图
源码地址
https://github.com/obliviouss...
说明
下载ueditor或neditor源码,拷贝到static目录下面
然后修改ueditor.config.js配置文件
在vue项目的main.js添加ueditor引用
新建3个页面 home,tab1,tab2。tab1和tab2是home下面的子页面
在router-view外面一定要添加keep-alive组件和transition组件,不然ueditor实例无法保存
在components文件夹下面新建一个editor作为编辑器的公共组件
在tab1中调用editor,同时要传入一个id并在editor页面接受,注意如果需要多个实例,id一定不能相同
<template>
<div>
<editor ref="editor" id="tab1Editor"></editor>
<button @click="getContent" class="m-t-10">获取内容</button>
<div>
<span>当前富文本编辑器内容是: {{content}}</span>
</div>
</div>
</template>
<script>
import Editor from '@/components/editor'
export default {
name: 'tab1',
components: { Editor },
data() {
return {
content:''
}
},
methods: {
//获取内容
getContent(){
this.content = this.$refs.editor.content
}
}
}
</script>
<style scoped>
.m-t-10{
margin-top: 10px;
}
</style>
editor页面代码,因为我们在router-view套用了keep-alive,所以ueditor的初始化一定要放在activated里面,
确保每次进入页面都会重新渲染ueditor,在deactivated里面调用ueditor的destroy方法,确保每次离开页面的时候
会销毁编辑器实例,这样就可以渲染多个ueditor实例了,并且每次切换都能保存编辑器的内容。
如果多个tab只需要一个实例请调用reset()方法
<template>
<div>
<div :id="this.id"></div>
</div>
</template>
<script>
export default {
name: 'editor',
props: ['id'],
data() {
return {
ue: '', //ueditor实例
content: '', //编辑器内容
}
},
methods: {
//初始化编辑器
initEditor() {
this.ue = UE.getEditor(this.id, {
initialFrameWidth: '100%',
initialFrameHeight: '350',
scaleEnabled: true
})
//编辑器准备就绪后会触发该事件
this.ue.addListener('ready',()=>{
//设置可以编辑
this.ue.setEnabled()
})
//编辑器内容修改时
this.selectionchange()
},
//编辑器内容修改时
selectionchange() {
this.ue.addListener('selectionchange', () => {
this.content = this.ue.getContent()
})
}
},
activated() {
//初始化编辑器
this.initEditor()
},
deactivated() {
//销毁编辑器实例,使用textarea代替
this.ue.destroy()
//重置编辑器,可用来做多个tab使用同一个编辑器实例
//如果要使用同一个实例,请注释destroy()方法
//this.ue.reset()
}
}
</script>在vue中创建多个ueditor实例的更多相关文章
- 在kubernetes集群中创建redis主从多实例
分类 > 正文 在kubernetes集群中创建redis主从多实例 redis-slave镜像制作 redis-master镜像制作 创建kube的配置文件yaml 继续使用上次实验环境 ht ...
- 在vue中创建自定义指令
原文:https://dev.to/ratracegrad/creating-custom-directives-in-vue-58hh 翻译:心上有杨 指令是带有 v- 前缀的特殊属性.指令的作用是 ...
- vue 中 使用百度编辑器 UEditor
(单页应用,多编辑器也可行) 新建一个Ueditor.vue组件对象,该组件用来封装ueditor,用来进行复用. <template> <div> <!--下面通过传递 ...
- vue中创建全局单文件组件/命令
1.在 vue中如果我们使用基于vue.js编写的插件,我们可以使用Vue.use() 如在main.js中: 2.添加全局命令,让每个vue单文件组件都可以使用到: 第一步:最好建一个全局的命令文件 ...
- vue中创建js文件使用export抛出函数,import引入后不能绑定HTML的问题
在es6中使用export和import实现模块化: js文件: export function test(x) { console.log(x); } vue组件: import {test} fr ...
- 主线程中创建不同的handler实例,接收消息会不会冲突
http://www.cnblogs.com/transmuse/archive/2011/05/16/2048073.html这篇博文讲的比较透彻,可参考. 当然结论是不会冲突.因为每个messag ...
- Vue中创建单文件组件 注册组件 以及组件的使用
<template> <div id="app"> <v-home></v-home> <hr > <br> ...
- vue中v-model动态生成的实例详解
每一行有一个input和一个select,其中行数是根据服务器返回的json数据动态变化的.那么问题来了,我们要怎样动态生成v-model? <template> <div> ...
- Vue动态创建注册component的实例代码
https://segmentfault.com/a/1190000015698278
随机推荐
- spring boot application.yml 常用基本配置
1.Tomcat 配置 server: #设置请求端口 port: 8080 servlet: #指定 Tomcat的请求路径 context-path: /cl #设置 Tomcat 编码格式 en ...
- TypeScript学习第二天:认识ts的数据类型
目录 1,类型总览 2,基本类型 2.1,布尔 2.2,数字 2.3,字符串 2.4,Null 2.5,undefined 2.6,symbol 2.7,bigint 3,引用类型 3.1,数组 Ar ...
- java中如何将嵌套循环性能提高500倍
java中如何将嵌套循环性能提高500倍 转载请注明出处https://www.cnblogs.com/funnyzpc/p/15975882.html 前面 似乎上一次更新在遥远的九月份,按照既定的 ...
- 如何使用在线工具手动验证JWT签名
如何使用在线工具手动验证JWT签名 先丢一个转换地址:https://cryptii.com/ 首先: jwt分为三个部分:header,payload,verifysignature ...
- [转载]MATLAB中神经网络的函数
1.设计函数 solvein 设计线性网络: solverb 设计径向基网络: solverbe 设计精确的径向 ...
- Cloud Computing Chapter3 (云计算第三章)
本篇文章是对课程大型软件系统设计与体系结构(双语)[又名:云计算]的课堂内容总结,适用于大连交通大学. Cloud Computing Chapter3 Understanding Cloud Com ...
- thinkphp5 composer安装phpexcel插件及使用
1: 首先composer加载phpexcel插件 composer require phpoffice/phpexcel 2: 页面引入 use PHPExcel_IOFactory; use PH ...
- 关于vue3的inheritAttrs属性和$attrs的部分用法
当我们在父组件中想要为子组件的某一个标签添加一些样式(注意,这里的是指attributes,css样式只是其中一种属性而已) <show-message id="lkx" c ...
- CentOS停更;阿里发布全新操作系统(Anolis OS)
镜像下载.域名解析.时间同步请点击阿里云开源镜像站 Linux系统对于Java程序员来说,就好比"乞丐手里的碗",任何业务都离不开他的身影,因为服务端的广泛使用,也因此衍生出了各种 ...
- 记mysql5.7错误only_full_group_by
错误截图为上 mysql版本:5.7.35-0ubuntu0.18.04.1 "this is incompatible with sql_mode=only_full_group_by&q ...