我是靠谱客的博主 粗暴冰淇淋,这篇文章主要介绍vue富文本编辑器使用(简单粗暴复制即可用)1、下载插件2、封装富文本组件3、使用组件,现在分享给大家,希望可以做个参考。

1、下载插件

npm i wangeditor --save
插件官网地址:https://www.wangeditor.com/

2、封装富文本组件

复制代码
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template lang="html"> <div class="editor"> <!-- <div ref="toolbar" class="toolbar"></div> --> <div ref="editor" class="text"></div> </div> </template> <script> import E from 'wangeditor' export default { name: 'editoritem', data() { return { // uploadPath, editor: null, info_: null } }, model: { prop: 'value', event: 'change' }, props: { value: { type: String, default: '' }, isClear: { type: Boolean, default: false } }, watch: { isClear(val) { // 触发清除文本域内容 if (val) { this.editor.txt.clear() this.info_ = null } }, value: function(value) { if (value !== this.editor.txt.html()) { this.editor.txt.html(this.value) } } //value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值 }, mounted() { this.seteditor() }, beforeDestroy() { // 调用销毁 API 对当前编辑器实例进行销毁 this.editor.destroy() this.editor = null }, methods: { seteditor() { this.editor = new E( this.$refs.editor) // this.editor.customConfig = this.editor.customConfig ? this.editor.customConfig : this.editor.config; // 配置 server 上传图片接口地址 // this.editor.config.uploadImgServer = '/upload-img' this.editor.config.onchange = (html) => { this.info_ = html // 绑定当前值 this.$emit('change', this.info_) // 将内容同步到父组件中 } // 自定义 alert this.editor.config.customAlert = function (s, t) { switch (t) { case 'success': this.$Message.success(s) break case 'info': this.$Message.info(s) break case 'warning': this.$Message.warning(s) break case 'error': this.$Message.error(s) break default: this.$Message.info(s) break } } // 配置全屏功能按钮是否展示 this.editor.config.showFullScreen = false // 创建富文本编辑器 this.editor.create() this.editor.txt.html(this.value) // 重新设置编辑器内容 } } } </script> <style lang="scss"> .editor { width: 100%; margin: 0 auto; position: relative; z-index: 0; } .toolbar { border: 1px solid #ccc; } .text { border: 1px solid #ccc; min-height: 200px; .w-e-text-container{ height: 200px!important; } .w-e-text{ min-height: 200px; } } </style>

3、使用组件

复制代码
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
<template> <div> <wangEnduit v-model="Content" :isClear="isClear" @change="change" :value="Content" /> </div> </template> <script> export default { components: { wangEnduit: () => import('@/components/wangEnduit/index'), }, data(){ return{ Content:"", isClear: false, } }, methods:{ change(val) { console.log('val',val) }, } } </script> <style> </style>

最后

以上就是粗暴冰淇淋最近收集整理的关于vue富文本编辑器使用(简单粗暴复制即可用)1、下载插件2、封装富文本组件3、使用组件的全部内容,更多相关vue富文本编辑器使用(简单粗暴复制即可用)1、下载插件2、封装富文本组件3、使用组件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部