在vue中使用Ueditor
2024-08-27 01:01:52
今天研究的主角是:UEditor
UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量、可定制、用户体验优秀等特点。
版本有很多
我用的是:[1.4.3.3 PHP 版本] UTF-8版
下载地址:http://ueditor.baidu.com/website/download.html
安装下载之后,将插件解压放在static目录下: static/ue/
修改ueditor.config.js,配置目录 :
window.UEDITOR_HOME_URL = "/static/ue/";
ps:这个插件的代码写的真的是”与众不同“,如果你用eslint检查代码,并且是个强迫症患者,那就很欢乐了。
下面是相关代码:
新建组件 /src/base/ueditor/ueditor.vue
<template>
<div>
<script id="editor" type="text/plain"></script>
</div>
</template>
<script>
export default {
name: "ue",
data() {
return {
editor: null
};
},
props: {
value: "",
config: {}
},
mounted() {
const _this = this;
this.editor = window.UE.getEditor("editor", this.config);
// 初始化UE
this.editor.addListener("ready", function() {
_this.editor.setContent(_this.value);
// 确保UE加载完成后,放入内容。
});
},
methods: {
getUEContent() {
// 获取内容方法
return this.editor.getContent();
}
},
destroyed() {
this.editor.destroy();
}
};
</script>
在组件中引用
<template>
<div>
<Ueditor :value="ueditor.value" :config="ueditor.config" ref="ue"></Ueditor>
<input type="button" value="显示编辑器内容(从控制台查看)" @click="returnContent">
</div> </template> <script>
import Ueditor from "../../base/ueditor/ueditor";
export default {
data() {
return {
dat: {
content: "",
},
ueditor: {
value: "编辑默认文字",
config: {}
}
};
},
methods: {
returnContent() {
this.dat.content = this.$refs.ue.getUEContent();
console.log(this.dat.content);
},
showContent() {
this.show = !this.show;
}
},
components: {
Ueditor
}
};
</script>
下面来看看要实现的效果:
最新文章
- Android Studio :enable vt-x in your bios security,已经打开还是报错的解决方法
- [SQL] SQL学习笔记之基础操作
- 改善你的jQuery的25个步骤 千倍级效率提升
- 纯css来画图-border应用
- Linux基本权限学习
- .htaccess
- Ubuntu 16.04 nvidia安装
- html的解析
- windows上使用image库
- UnrealEngine4 PBR Shading Model 概述
- JAVA toString方法
- 个人.net学习规划路线
- 未能从文本";Template";创建 ";System.Windows.DependencyProperty";
- Qt编译
- 简单说明如何设置系统中的NLS_LANG环境变量
- 解决python本地离线安装requests问题
- 学习oracle存储过程
- Java框架spring 学习笔记(十五):操作MySQL数据库
- Ubuntu菜鸟入门(十七)—— E: Sub-process /usr/bin/dpkg returned an error code (1) 出错解决方案
- vim保存只读文件时获得sudo权限
热门文章
- 两个变量交换数字 不用第三个变量的情况下 int a = 5,b = 6
- FIT文件CRC校验
- layDate——初步使用
- .Net Core 商城微服务项目系列(八):购物车
- SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决
- win10下使用Linux命令
- 阿里云Centos操作Mysql
- 利用shell脚本个性化运行jar任务
- 每个新手程序员都必须知道的Python技巧
- 重载operator new delete函数