vue使用wangEditor富文本

目录

1、安装wangEditor

2、引入wangEditor

3、使用wangEditor

4、使用wangEditor的事件回调


1、安装wangEditor

首先,需要安装wangEditor。可以通过npm或yarn来安装:

bashnpm install wangeditor --save
bashyarn add wangeditor

2、引入wangEditor

在Vue组件中引入wangEditor,需要在组件的<script>标签中添加以下代码:

javascriptimport wangeditor from 'wangeditor'
import 'wangeditor/dist/css/wangEditor.min.css'

3、使用wangEditor

在Vue组件的<template>标签中添加以下代码,用于显示wangEditor编辑器:

html<div ref="editor"></div>

在Vue组件的<script>标签中添加以下代码,用于初始化wangEditor编辑器:

javascriptexport default {
mounted () {
this.initEditor()
},
methods: {
initEditor () {
const editor = new wangeditor(this.$refs.editor)
editor.create()
// 获取编辑器内容
const content = editor.getContent()
console.log(content)
}
}
}

initEditor方法中,首先创建了一个新的wangEditor实例,并传入this.$refs.editor作为编辑器的容器。然后,调用editor.create()方法创建编辑器。最后,使用editor.getContent()方法获取编辑器的内容,并在控制台中打印出来。

4、使用wangEditor的事件回调

wangEditor提供了多种事件回调,可以在编辑器中实现各种功能。例如,可以使用ready事件回调来监听编辑器的加载完成事件:

javascriptinitEditor () {
const editor = new wangeditor(this.$refs.editor)
editor.config.customConfig = {
ready: function () {
console.log('wangEditor ready')
}
}
editor.create()
}

ready回调函数中,可以执行一些需要在编辑器加载完成后执行的代码。例如,可以在控制台中输出一条消息,表示wangEditor已经加载完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值