
tinymce 监听附件变动失灵的解决办法
在使用附件插入插件时,您遇到了无法监听附件插入和删除变动的难题。以下是如何解决此问题的方法:
解决方案:
- 去掉富文本编辑器上的 v-model。
- 在初始化编辑器时加入以下回调:
editor.on("nodechange", (e) => {
console.log("node change:", e.element.outerhtml);
});- 监听编辑器 value 的变化,并解决光标问题:
watch: {
editorvalue(val) {
if (this.editorcursorpositon) {
this.editor.selection.setcursorlocation(this.editorcursorpositon);
}
console.log("value:", val);
},
},- 在 methods 中加入以下方法:
methods: {
afterattachupload(attachment) {
this.editor.selection.select(
this.editor.dom.getparent(attachment, "figure")
);
this.$emit("attachments", this.editorvalue);
},
},- 在成功插入附件后再次调用 afterattachupload 方法:
// before insert attachment this.afterAttachUpload(attachment);










