当前位置:网站首页>wangeditor封装插件初步
wangeditor封装插件初步
2022-06-21 10:25:00 【极梦网络无忧】
安装
安装 editor
yarn add @wangeditor/editor
# 或者 npm install @wangeditor/editor --save
安装 Vue3 组件
yarn add @wangeditor/editor-for-[email protected]
# 或者 npm install @wangeditor/editor-for-[email protected] --save
在组件中
如果有别的需求,可以自行修改
<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>
引用
<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>
边栏推荐
- 金融机构抢滩“数字员工”;保险APP适老化服务评测框架发布
- Unity中的地平面简介
- Inner class
- 嵌入式软件项目流程、项目启动说明书(示例)
- NLog自定义Target之MQTT
- Xidian AI ranked higher than Qingbei in terms of AI major, and Nantah ranked first in China in terms of Software Science in 2022
- 应用配置管理,基础原理分析
- TC software outline design document (mobile group control)
- The spingboot microservice is packaged into a docker image and connected to the database
- 安全百强 中坚力量!美创科技入选《2022年中国数字安全百强报告》
猜你喜欢

使用shapeit进行单倍型分析

Are you still using localstorage directly? The thinnest in the whole network: secondary encapsulation of local storage (including encryption, decryption and expiration processing)

leetcode:715. Range 模块【无脑segmentTree】

Classification of ram and ROM storage media

WCF restful+jwt authentication

The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised

Dapr advanced-01-debug dapr

Unable to access gcr IO solutions

Optimisation des performances - compression, chargement et formatage des images

Talk about the multimodal project of fire
随机推荐
2022年中总结-一步一个脚印,踩出柳暗花明
NLog自定义Target之MQTT
给电脑加装固态
嵌入式软件项目流程、项目启动说明书(示例)
触摸按键控制器TTP229-BSF使用心得[原创cnblogs.com/helesheng]
K-means introduction
安全百强 中坚力量!美创科技入选《2022年中国数字安全百强报告》
115. secondary packaging of table components
【云驻共创】企业数字化加速“新智造”
New programmers optimize a line of code on Monday and are discouraged on Wednesday?
Will the thunderstorm of Celsius be the "Lehman moment" in the field of encryption?
音视频格式简介、编解码、音视频同步
AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...
为什么 C# 访问 null 字段会抛异常?
中国国际电子商务中心与易观分析联合发布:2021年4季度全国网络零售发展指数同比增长0.6%
Dapr advanced -02- view dapr logs
The first phase of takin open source training camp is coming! Teach you to complete the full link voltage test hand in hand!
Leader: who uses redis expired monitoring to close orders? Get out of here!
Arcore supported devices
ENGRAIL THERAPEUTICS公布ENX-101临床1b研究正面结果