wangeditor富文本编辑器
1.init
复制代码
1
2
3https://www.wangeditor.com/ npm i wangeditor --save
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<template> <div class="editor" ref="editor"></div> </template> <script> import Vue from 'vue' import E from 'wangeditor' export default Vue.extend({ name: 'TextEditor', props: { value: { type: String, default: '' } }, mounted () { this.init() }, methods: { init () { const editor = new E(this.$refs.editor) // 更改内容触发的回调 // 配置 onchange 回调函数 editor.config.onchange = (newHtml) => { console.log('change 之后最新的 html', newHtml) this.$emit('input', newHtml) } editor.create() // 设置初始值 editor.txt.html(this.value) } } }) </script> <style lang="scss" scoped> </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<template> <div class="course"> <TextEditor v-model="editorText"></TextEditor> </div> </template> <script lang="ts"> import Vue from 'vue' import TextEditor from '@/components/TextEditor/index.vue' export default Vue.extend({ name: 'Course', components: { TextEditor }, data () { return { editorText: '<h1>react<h1/>' } } }) </script> <style lang="scss" scoped> </style>
最后
以上就是激动钥匙最近收集整理的关于wangeditor富文本编辑器的使用的全部内容,更多相关wangeditor富文本编辑器内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复