官网:https://www.wangeditor.com/v5/getting-started.html
<template>
<div ref="websiteEditorElem" style="height:auto;"></div>
</template>
<script>
import E from 'wangeditor'
export default {
props: {
// 配置菜单栏
menus: {
type: Array,
default: () => {
return [
'head',
'bold',
'fontSize',
'fontName',
'italic',
'underline',
'strikeThrough',
'indent',
'lineHeight',
'foreColor',
'backColor',
// 'link',
'list',
// 'todo',
'justify',
'quote',
// 'emoticon',
'image',
// 'video',
'table',
// 'code',
'splitLine',
'undo',
'redo'
]
}
},
// 初始化
initContent: {
type: String,
default: ''
}
},
components: {},
data() {
return {}
},
mounted() {
var editor = new E(this.$refs.websiteEditorElem)
// 配置菜单栏,删减菜单,调整顺序
editor.config.menus = this.menus
// 兼容老版本
editor.customConfig = editor.customConfig ? editor.customConfig : editor.config
// 获取内容 html、text、JSON
editor.customConfig.onchange = html => {
// console.log('html', html) // 获取html
var txt = editor.txt.text() // 获取文本
// console.log('txt', txt)
var json = editor.txt.getJSON() // 获取 JSON 格式的内容
var jsonStr = JSON.stringify(json)
// console.log('jsonStrjsonStr', jsonStr)
this.$emit('getwangeditorChange', html, txt, jsonStr)
}
// 编辑区域高度默认为 300px
editor.config.height = 300
// 限制大小 默认限制图片大小是 5M
// editor .config.uploadImgMaxSize = 2 * 1024 * 1024 // 2M
// 限制类型 如果不希望限制类型,可将其设为空数组
editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
// 隐藏插入网络图片的功能
editor.config.showLinkImg = false
// base64 保存图片
editor.config.uploadImgShowBase64 = true
// 关闭粘贴样式的过滤
editor.config.pasteFilterStyle = false
// 忽略粘贴内容中的图片
editor.config.pasteIgnoreImg = true
// 隐藏菜单栏提示
editor.config.showMenuTooltips = true
// 设置菜单栏提示为上标还是下标
// editor.config.menuTooltipPosition = 'down' // 'up'
// 配置全屏功能按钮是否展示
editor.config.showFullScreen = true
// 自定义 placeholder 的提示文字。
editor.config.placeholder = '请输入'
// 配置行高
// editor.config.lineHeights = ['1', '1.15', '1.6', '2', '2.5', '3']
// 编辑器初始化时,默认会自动 focus 到编辑区域
// editor.config.focus = false
editor.create()
// 初始化内容
editor.txt.html(this.initContent)
}
}
</script>