baozhengrui

导航

多行输入enter发送,enter+shif换行


<textarea-->
<!--            id="input-id"-->
<!--            class="transparent-input1"-->
<!--            :rows="2"-->
<!--            placeholder="请输入内容,Shift+Enter换行"-->
<!--            v-model="resultShow"-->
<!--            @keydown="handleKeydown"-->
<!--        ></textarea>-->


handleKeydown(event) {
      if (event.key === 'Enter' && event.shiftKey) {
        // Shift + Enter for newline
        const cursorPos = event.target.selectionStart;
        this.textarea =
            this.textarea.substring(0, cursorPos) + '\n' + this.textarea.substring(cursorPos);
        this.$nextTick(() => {
          event.target.selectionStart = cursorPos + 1;
          event.target.selectionEnd = cursorPos + 1;
        });
        event.preventDefault();
      } else if (event.key === 'Enter' && !event.shiftKey) {
        // Enter for submit
        this.open();
        event.preventDefault();
      }
    },

posted on 2024-10-11 09:35  芮艺  阅读(3)  评论(0编辑  收藏  举报