React wangEditor 自定义菜单

wangEditor 初始化

在使用wangeditor的过程中,我们可以根据自己的需求自定义菜单

首先我们看wangEditor的引入过程:

导入:

import E from 'wangeditor';

创建区域:

  <div id="div1" ></div>

初始化:

	componentDidMount() {
	   
		const defaultMenu=[ 'head','bold', 'fontSize','fontName','italic','underline','foreColor','undo','redo','justify',]
		const editor = new E('#div1')
			editor.config.onchange=html=>{
				   this.setState({
					    editorContent:html
				    })
			}
			editor.config.menus=defaultMenu
			editor.zIndex.baseZIndex = 100
			editor.config.withCredentials = true
			editor.create();

	}

实现效果:

自定义菜单

开始自定义菜单,还是上面的类中操作:

引入菜单:

const {$, BtnMenu }=E;

创建菜单类:

class Image2 extends BtnMenu {
	constructor(editor){
		const $elem = $(
			`<div class="w-e-menu" data-title="图片">
				<i class="w-e-icon-image">
				</i>
			</div>`
		)
		super($elem, editor)
	}
	// 菜单点击事件
	clickHandler(){
		console.log(1);
	}
	tryChangeActive(){
		    const editor = this.editor
		    if (editor.cmd.queryCommandState('image2')) {
		        this.active()
		    } else {
		        this.unActive()
		    }
	}
}

完善:

	componentDidMount() {
	    const menuKeyVideo = "image2"
		const defaultMenu=[ 'head','bold', 'fontSize','fontName','italic','underline','foreColor','undo','redo','justify',]
		E.registerMenu(menuKeyVideo,Image2)
		const editor = new E('#div1')
	    editor.config.onchange=html=>{
				   this.setState({
					    editorContent:html
				    })
		 }
		editor.config.menus=defaultMenu
		editor.zIndex.baseZIndex = 100
		editor.config.withCredentials = true
		editor.create();
	}

查看效果:

 点击图片查看效果:

 希望对你有所帮助

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值