vue2.0项目中使用百度Ueditor富文本编辑器
2018-11-22 16:11
615 查看
版权声明: https://blog.csdn.net/xiasohuai/article/details/84342701
1.首先下载静态文件
https://ueditor.baidu.com/website/download.html
2.然后,进行配置
首先把官网下载的Ueditor资源,放入静态资源src/static中。
修改ueditor.config.js中的window.UEDITOR_HOME_URL配置,如下图:
3.在main.js中引入
[code]import '../static/utf8-jsp/ueditor.config.js' import '../static/utf8-jsp/ueditor.all.min.js' import '../static/utf8-jsp/lang/zh-cn/zh-cn.js' import '../static/utf8-jsp/ueditor.parse.min.js'
4.开发公共组件
开发公共组件,可设置填充内容defaultMsg,配置信息config(宽度和高度等),并提供获取内容的方法。
[code]<template> <div> <script id="editor" type="text/plain"></script> </div> </template> <script> export default { name: 'UE', data () { return { editor: null } }, props: { defaultMsg: { type: String }, config: { type: Object } }, mounted() { const _this = this; this.editor = UE.getEditor('editor', this.config); // 初始化UE this.editor.addListener("ready", function () { _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后,放入内容。 }); }, methods: { getUEContent() { // 获取内容方法 return this.editor.getContent() } }, destroyed() { this.editor.destroy(); } } </script>
5.使用
当我们需要使用富文本编辑器时,直接调用公共组件即可
[code]<template> <div class="components-container"> <button @click="getUEContent()">获取内容</button> <div class="editor-container"> <UE :defaultMsg=defaultMsg :config=config ref="ue"></UE> </div> </div> </template> <style> .info{ border-radius: 10px; line-height: 20px; padding: 10px; margin: 10px; background-color: #ffffff; } </style> <script> import UE from '../../components/ue/ue.vue'; export default { components: {UE}, data() { return { defaultMsg: '这里是UE测试', config: { initialFrameWidth: null, initialFrameHeight: 350 } } }, methods: { getUEContent() { let content = this.$refs.ue.getUEContent(); console.log(content) } } }; </script>
如果有严格模式报错
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them...
这个问题是因为项目中的使用的babel默认添加了use strict造成,可参考 https://segmentfault.com/q/1010000007415253
我采用的是链接中答案的第三种方式:添加了babel-plugin-transform-remove-strict-mode,并在.babelrc里添加下列代码
[code]{ "plugins": ["transform-remove-strict-mode"] }
注:ES6的模块自动采用严格模式,不管你有没有在模块头部加上"use strict";
效果图如下:
阅读更多
相关文章推荐
- vue集成百度UEditor富文本编辑器使用教程
- 百度富文本编辑器ueditor使用
- 使用百度富文本编辑器UEditor碰到的问题
- WEB项目中使用UEditor(富文本编辑器)
- UEditor(百度富文本编辑器)的暴力使用
- javaWEB中百度富文本编辑器UEditor1.4.3的使用随笔
- 百度开源富文本编辑器 UEditor配置:图片上传和文件上传独立使用方法
- 百度富文本编辑器ueditor的使用、非空校验、引用预定义模板
- 百度富文本编辑器ueditor在jsp中的使用(ssm框架中的应用)
- 使用百度的富文本编辑器UEditor遇到的问题总结
- 使用百度富文本编辑器UEditor碰到的问题
- 百度富文本编辑器ueditor使用总结
- 百度 ueditor 富文本编辑器的使用心得 jsp版本 1.4的JDK weblogic8
- 百度富文本编辑器ueditor使用小结
- 在python web.py中使用百度富文本编辑器 UEditor
- 百度富文本编辑器ueditor使用总结
- spring boot 、springMVC环境集成百度ueditor富文本编辑器,使用七牛云存储图片
- 百度ueditor富文本编辑器使用初体验
- 百度富文本编辑器UEditor的使用总结
- 百度Web富文本编辑器ueditor在ASP.NET MVC3项目中的使用说明