安装
安装 editor
复制代码
1
2
3yarn add @wangeditor/editor # 或者 npm install @wangeditor/editor --save
安装 Vue3 组件
复制代码
1
2
3yarn add @wangeditor/editor-for-vue@next # 或者 npm install @wangeditor/editor-for-vue@next --save
在组件中
如果有别的需求,可以自行修改
复制代码
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<template> <div style="border: 1px solid #ccc"> <Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig" :mode="mode" /> <Editor style="height: 500px; overflow-y: hidden;" v-model="valueHtml" :defaultConfig="editorConfig" :mode="mode" @onCreated="handleCreated" /> </div> </template> <script> import '@wangeditor/editor/dist/css/style.css' // 引入 css import { onBeforeUnmount, ref, shallowRef, onMounted ,getCurrentInstance} from 'vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue' const editorRef = shallowRef() // 内容 HTML const valueHtml = ref('<p>hello</p>') const toolbarConfig = {} const editorConfig = { placeholder: '请输入内容...' } export default { components: { Editor, Toolbar }, data() { return { editorRef, valueHtml, mode: 'default', // 或 'simple' toolbarConfig, editorConfig, } }, props:{ // 绑定值 htmlval: {}, }, mounted() { this.parseJv() }, methods:{ parseJv(){ console.log(this.htmlval) setTimeout(() => { valueHtml.value = this.htmlval;// '<p>模拟 Ajax 异步设置内容</p>' }, 500) }, handleCreated(editor) { editorRef.value = editor // 记录 editor 实例,重要! } }, BeforeUnmount(){ const editor = editorRef.value if (editor == null) return editor.destroy() }, setup() { // // 组件销毁时,也及时销毁编辑器 // const handleCreated = (editor) => { // editorRef.value = editor // 记录 editor 实例,重要! // } // return { // handleCreated // }; } } </script>
引用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18<template> <WangEditor :htmlval="htmlStr" /> </template> <script> // This starter template is using Vue 3 <script setup> SFCs // Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup import WangEditor from './components/form/WangEditor.vue' export default { components: {WangEditor }, data() { return { htmlStr: '<p>helloasd1</p>', } }, } </script>
最后
以上就是花痴白猫最近收集整理的关于wangeditor封装插件初步的全部内容,更多相关wangeditor封装插件初步内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复