textarea实现回车发送,ctrl+enter换行

html:

        <el-input
          type="textarea"
          autofocus="true"
          @keydown.native="handleKeyCode($event)"
          resize="none"
          v-model="messageTxt"
          maxlength="2000"
          show-word-limit
        >
        </el-input>

js:

// 键盘回车事件
    handleKeyCode(event) {
      if (event.keyCode == 13) {
        if (!event.metaKey) {
          event.preventDefault();
          this.handleTextSend();
        } else {
          this.messageTxt = this.messageTxt + '\n';
        }
      }
    },
// 发送消息
handleTextSend() {

}

  

posted @ 2020-01-07 11:32  狗尾草的博客  阅读(4779)  评论(1编辑  收藏  举报