❤ 前言
中文文档: 点击此处
❤ 第一步 安装
1.安装 Vue2 组件yarn add @wangeditor/editor-for-vue
2.CDN导入
<!-- 引入 css -->
<link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
<!-- 引入 js -->
<script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
<script>
var E = window.wangEditor; // 全局变量
</script>
❤ 第二步 使用
话不多说直接上代码
<div style="border: 1px solid #DDDDDD;">
<div id="toolbar"></div>
<div id="editor" style="height: 600px;border-top: 1px solid #DDDDDD;"></div>
</div>
const Editor = window.wangEditor
mounted(){
this.initEditor()
},
methods:{
initEditor() {
const editorConfig = {}
editorConfig.placeholder = '请输入内容'
editorConfig.onChange = (editor) => {
// 当编辑器选区、内容变化时,即触发
console.log('html', editor.getHtml())
}
const editor = Editor.createEditor({
selector: '#editor',
config: editorConfig,
html: this.editorContent,
mode: 'default' // 或 'simple' 参考下文
})
// 工具栏配置
const toolbarConfig = {
toolbarKeys: [
// 菜单 key
'headerSelect',
"blockquote",
// 分割线
'|',
"underline",
// 菜单 key
'bold',
'italic',
// 菜单组,包含多个菜单
{
key: 'group-more-style', // 必填,要以 group 开头
title: '...', // 必填
iconSvg: '<svg>....</svg>', // 可选
menuKeys: ["through", "code", "clearStyle"] // 下级菜单 key ,必填
},
"color",
"bgColor",
'|',
"fontSize",
"fontFamily",
"lineHeight",
'|',
"bulletedList",
"numberedList",
"indent",
"delIndent",
'|',
"emotion",
"insertLink",
"insertImage",
]
}
const toolbar = Editor.createToolbar({
editor,
selector: '#toolbar',
config: toolbarConfig,
mode: 'default' // 或 'simple' 参考下文
})
},
}
❤ 总结
Thanks♪(・ω・)ノ,到此就结束了,有什么问题都可以问!
欢迎评论 / 私信我~