You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue中TinyMCE新增其他工具栏后自定义按钮失效问题

问题原因
  1. 工具栏配置字符串拼接时缺少空格:你配置toolbar时的拼接写法'forecolor backcolor' + 'customInsertButton'最终生成的字符串是forecolor backcolorcustomInsertButton,TinyMCE会把backcolorcustomInsertButton识别为一个不存在的控件名,导致对应控件都无法正常加载。
  2. 自定义按钮注册名与引用名不匹配:你在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('&nbsp;<b>It\'s my button!</b>&nbsp;')
      },
    })
  },
})

内容的提问来源于stack exchange,提问作者Gleb Pristupa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.22 04:45:06