1、新建wangEditor组件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51<template> <div class="editor-wang"> <div id="wangEditor"></div> </div> </template> <script> // 引入 wangEditor import wangEditor from "wangeditor"; export default { data() { return { editor: null, editorData: ``, }; }, props: { editorDetail: String, }, mounted() { const editor = new wangEditor(`#wangEditor`); // 配置 onchange 回调函数,将数据同步到 vue 中 editor.config.onchange = (newHtml) => { this.editorData = newHtml; }; editor.config.uploadImgServer = "https://www.gkh0305.top:8081/uploads"; editor.config.uploadFileName = "uploadFiles"; editor.config.uploadImgMaxSize = 5 * 1024 * 1024; // 5M // 创建编辑器 editor.create(); this.editor = editor; setTimeout(()=>{ this.editor.txt.html(this.editorDetail); },1000) }, methods: { getEditorData() { // 通过代码获取编辑器内容 let data = this.editor.txt.html(); return data; }, }, beforeDestroy() { // 调用销毁 API 对当前编辑器实例进行销毁 this.editor.destroy(); this.editor = null; }, }; </script>
2、使用组件
复制代码
1<editor-wang class="editor" :editorDetail="user_detail" ref="editor" ></editor-wang>
3、获取富文本编辑器内容
复制代码
1this.user_detail = this.$refs.editor.getEditorData();
最后
以上就是甜美钢笔最近收集整理的关于vue项目中使用富文本编辑器(wangEditor)的全部内容,更多相关vue项目中使用富文本编辑器(wangEditor)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复