wangeditor自定义菜单, vue

1、新建editorMenu. js

创建菜单

import E form 'wangeditor'
const {$,BtnMenu} = E
import {state} from './observer'

export class Video1 extends BtnMenu {
	constructor(editor){
		const $elem = $(
			`<div class"w-e-menu" data-title="视频">
				<i class="w-e-icon-play"></i>
			</div>`
		)
		super($elem, editor)
	}
	// 菜单点击事件
	clickHandler(){
		// 弹框自定义视频列表
		state.selVideoDialog = true
	}
	// 尝试修改菜单 active状态,不改就不写,比如加粗要标亮的时候使用
	tryChangeActive(){}
}

export class Voice1 extends BtnMenu {
	constructor(editor){
		const $elem = $(
			`<div class"w-e-menu" data-title="音频">
				<i class="w-e-icon-microphone"></i>
			</div>`
		)
		super($elem, editor)
	}
	// 菜单点击事件
	clickHandler(){
		// 弹框自定义音频列表
		state.selVoiceDialog = true
	}
	// 尝试修改菜单 active状态
	tryChangeActive(){}
}

2、使用编 辑器的vue文件中引入

import E form " wangeditor"
import {Video1,Voice1} form "./ editorMenu.js"

<div height="100%" id=" editorBox"></div>

mounted(){
      const menuKeyVideo = "video"
      const menuKeyVoice = "voice"
      this.editor = new E("# editorBox")
		// 全局注册自定义菜单video, voice
     E.registerMenu(menuKeyVideo,Video1)
     E.registerMenu(menuKeyVoice,Voice1)
      
	//创建编辑器
	this.editor.create()

}

3、js和vue直接传值,用于弹框显示,observable

中间件文件 observer.js

import Vue from "vue"

export const state = Vue. observable({
       selVideoDialog: false,
       selVoiceDialog: false
})

js中获取改值

import {state} form "./observe"
// 改值
state.selVideoDialog = true

// vue文件中使用
import {state} form "./observe"
 //使用  state.selVideoDialog=改值,显示用selVideoDialog

computed:{
     selVideoDialog(){
           return state.selVideoDialog
     }
}
Vue 3,可以使用Vue-wangeditor组件来集成wangEditor编辑器。以下是在Vue 3添加自定义内容的步骤: 1. 在Vue 3组件引入Vue-wangeditor组件。 ``` <template> <div> <vue-wangeditor v-model="content" :config="editorConfig"></vue-wangeditor> </div> </template> <script> import VueWangEditor from 'vue-wangeditor'; export default { components: { VueWangEditor, }, data() { return { content: '', editorConfig: { // 在这里配置编辑器 }, }; }, }; </script> ``` 2. 在editorConfig添加自定义菜单。在菜单的click属性,指定要执行的函数。例如,你可以添加一个名为“自定义菜单”的菜单,并将其单击事件绑定到myCustomFunction函数。 ``` data() { return { content: '', editorConfig: { menus: [ 'head', 'bold', 'italic', 'underline', 'strikeThrough', 'foreColor', 'backColor', 'link', 'list', 'justify', 'quote', 'emoticon', 'image', 'table', 'video', 'code', 'undo', 'redo', 'fullscreen', 'customMenu' ], customMenu: { title: '自定义菜单', type: 'click', click: () => { this.myCustomFunction(); } } }, }; }, methods: { myCustomFunction() { // 在光标处插入文本片段 this.$refs.editor.$editor.command(null, 'insertHtml', '这是一段自定义内容'); }, } ``` 3. 在myCustomFunction函数添加自定义的代码。例如,你可以在函数插入一个文本片段。 ``` myCustomFunction() { // 在光标处插入文本片段 this.$refs.editor.$editor.command(null, 'insertHtml', '这是一段自定义内容'); }, ``` 这样就可以在Vue 3添加自定义内容了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值