1.Ctrl+Enter换行,Enter键发送信息
<template>
<div class="line">
<span>输入框:</span>
<el-input
ref="textInput"
type="textarea"
v-model="inputVal"
@keyup.ctrl.enter.native="lineBreak"
@keydown.enter.exact.native="submit"
>
</el-input>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
const inputVal = ref();
const textInput = ref();
function lineBreak() {
const textarea = textInput.value.textarea;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const value = textarea.value;
const newValue = value.substring(0, start) + "\n" + value.substring(end);
textarea.value = newValue;
textarea.selectionStart = textarea.selectionEnd = start + 1;
}
function submit(e: any) {
e.preventDefault();
}
</script>
<style scoped lang="less">
.line{
display: flex;
margin:10px;
.el-textarea{
width:300px
}
}
</style>