Vue中TinyMCE新增其他工具栏后自定义按钮失效问题
问题原因
- 工具栏配置字符串拼接时缺少空格:你配置toolbar时的拼接写法
'forecolor backcolor' + 'customInsertButton'最终生成的字符串是forecolor backcolorcustomInsertButton,TinyMCE会把backcolorcustomInsertButton识别为一个不存在的控件名,导致对应控件都无法正常加载。 - 自定义按钮注册名与引用名不匹配:你在setup中注册的自定义按钮名为
customButton,但toolbar中引用的是customInsertButton,名称不一致导致TinyMCE找不到对应的自定义按钮配置。
解决方案
- 修正工具栏配置:所有控件名称之间必须用空格分隔,分段拼接字符串时要主动在连接处补空格
- 确保自定义按钮的注册名称和toolbar中引用的名称完全一致
正确配置示例:
tinyMCE.init({ selector: '#d1', // 写法1:直接写完整字符串,空格分隔所有控件 toolbar:'forecolor backcolor customButton', // 写法2:分段拼接的话连接处补空格 // toolbar: 'forecolor backcolor ' + 'customButton', setup(editor) { editor.addButton('customButton', { text: 'My button', icon: false, onclick() { editor.insertContent(' <b>It\'s my button!</b> ') }, }) }, })
内容的提问来源于stack exchange,提问作者Gleb Pristupa
相关产品推荐
相关产品推荐

