===
- 必须在创建编辑器之前注册
- 全局只能注册一次,不要重复注册
不管是注册什么样的菜单,是下拉select还是menubutton,文档上都有这两句话
确实,如果在一个项目里,重复注册会报错:
Error: Duplicated key 'xxx' in menu items
但是在一些特定的条件下,有没有这么一种可能
我就是需要一直注册一个菜单呢?
具体业务场景就不说明了
仅在这里给大家提供一种思路
不管是vue还是react还是其他的都可以用这个方法。反正现在客户端性能都很好,基本也不用考虑什么开销……
1.设一个变量存menu的name
const menuName = useRef("menu" + Math.random());
2.每次用这个menuName.current重新注册
// 定义菜单配置 const menuConf = { key: menuName.current, // menu key ,唯一。注册之后,可配置到工具栏 factory() { return new ConvertToLinkCard(); }, }; Boot.registerMenu(menuConf);
3.最后,toorbarkeys里面也用变量名menuName.current即可
toolbarKeys: [ "bold", "underline", "italic", "color", "bgColor", "clearStyle", "fontSize", "justifyLeft", "justifyRight", "justifyCenter", "justifyJustify", "divider", "insertTable", "uploadImage", menuName.current, "redo", "undo", ],