我有一个使用 tiptap 的协作聊天应用程序因为它是消息区域。我发现它很有用,因为它已经支持多种格式并且可以增加一些灵 active 。但是,我发现自己在寻找监听“输入”键的事件监听器时遇到了困难。当用户按下回车键时,我想提交他们的聊天并清除编辑器。
我找到了这个 onUpdate 事件监听器,但我找不到它检测按下的键的确切位置。
示例代码如下:
mounted() {
let editor = new Editor({
extensions: [StarterKit],
content: this.value
});
editor.on("update", e => {
console.log(e);
this.$emit("input", this.editor.getHTML());
});
this.editor = editor;
}
顺便说一句,我正在使用 Vue2。
谢谢
最佳答案
在编辑器 Prop 中,传入一个回调
handleDOMEvents: {
keydown: (view, event) => {
if (event.key === "Enter") {
}
return false;
}
},
https://www.tiptap.dev/api/editor/#editor-props https://prosemirror.net/docs/ref/#view.EditorProps
https://stackoverflow.com/questions/68814136/