【vue开发基础】之wangeditor富文本编辑器

11 篇文章 0 订阅
本文档介绍了如何在Vue2项目中安装和使用wangEditor富文本编辑器。首先,通过yarn添加组件并CDN导入css和js文件。然后,在Vue的mounted生命周期钩子中初始化编辑器,设置占位符、内容变更监听等功能,并自定义工具栏配置。文章结尾鼓励读者提问和交流。
摘要由CSDN通过智能技术生成


❤ 前言

中文文档: 点击此处


❤ 第一步 安装

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♪(・ω・)ノ,到此就结束了,有什么问题都可以问!
欢迎评论 / 私信我~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JS Lover

我会尽最大努力分享更多开发经验

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值