简体   繁体   English

"TipTap\/VueJS - 如何检测按键"

[英]TipTap/VueJS - How to detect a keypress

In the editor props, pass in a callback在编辑器道具中,传入一个回调

      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://www.tiptap.dev/api/editor/#editor-props https://prosemirror.net/docs/ref/#view.EditorProps

For reference, I managed to do something similar.作为参考,我设法做了类似的事情。 I use VueJS native keydown event to detect which key is pressed.我使用 VueJS 原生 keydown 事件来检测按下了哪个键。

<EditorContent class="editor" :editor="editor" @keydown.native="onKeydown" />
methods: {
  onKeydown(e) {
    if (!e.shiftKey && e.which == 13) {
      this.editor.commands.undo(); // i just "undo" the enter event to remove the space it made
      this.$emit("onEnter");
    }
  }
}

Reference:https://www.tiptap.dev/installation/vue2#5-use-v-model-optional参考:https ://www.tiptap.dev/installation/vue2#5-use-v-model-optional

  editorProps: {
    handleDOMEvents: {
      keypress: (view, event) => {
        if (event.key === 'Enter') {
          console.log('Heyyyy')
        }
      },
    },
  },

You can pass it as props to new Editor()您可以将其作为道具传递给 new Editor()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM