效果

TS部分:
<script lang="ts" setup>
import { Promotion } from '@element-plus/icons-vue'
import { ref } from 'vue';
const question = ref('')
const keyDownCode = ref(0)
const keyDownEnter = (e: any) => {
console.log(e.keyCode)
keyDownCode.value = e.keyCode
e.preventDefault()
}
const keyUpEnter = (e: any) => {
if (keyDownCode.value === 229) {
return
}
e.preventDefault()
console.log(e.keyCode)
send()
}
const keyEnterShift = () => {
console.log('shift,enter')
}
const send = () => {
question.value = ''
}
</script>
模板部分:
<template>
<div class="chat-input">
<div class="chat-inputcontainer">
<div class="input-inner">
<div class="editor">
<el-input class="editor-textarea" v-model="question" autosize type="textarea"
placeholder="在这里输入你的问题" @keydown.enter.exact="keyDownEnter" @keyup.enter.exact="keyUpEnter"
@keydown.enter.shift="keyEnterShift" />
</div>
<div class="toolbar">
<el-tooltip class="box-item" effect="dark" content="请输入你的问题" placement="top">
<el-button class="send" size="large" type="info" text>
<el-icon size="26">
<Promotion />
</el-icon>
</el-button>
</el-tooltip>
</div>
</div>
</div>
</div>
</template>
样式部分
<style lang="scss" scoped>
.chat-input {
position: relative;
.chat-inputcontainer {
position: relative;
background-color:
border: 1px solid
border-radius: 16px;
box-shadow: 0px 8px 25px 0px
overflow: hidden;
.input-inner {
display: flex;
flex-wrap: wrap;
background-color:
padding: 8px 16px;
.editor {
word-break: break-all;
flex-grow: 1;
color:
margin-right: -12px;
.editor-textarea:deep(.el-textarea__inner) {
width: 100%;
resize: none;
font-variation-settings: inherit;
font-weight: inherit;
letter-spacing: inherit;
font-family: inherit;
font-feature-settings: inherit;
font-size: 1rem;
line-height: 1.5rem;
padding: .5rem .75rem;
border-radius: 0;
appearance: none;
--tw-shadow: 0 0 transparent;
margin: 0;
max-height: 25dvh;
border-width: 0;
background-color: transparent;
padding-left: 0;
padding-right: 0;
color:
outline: none;
box-shadow: none;
:focus {
--tw-ring-inset: var(--tw-empty,
/*!*/
/*!*/
);
--tw-ring-offset-width: 0px;
--tw-ring-offset-color:
--tw-ring-color:
outline-offset: 2px;
outline: none;
border-color: inherit;
}
}
}
.toolbar {
display: flex;
gap: 4px;
color:
align-items: flex-end;
margin-left: auto;
.send {
border: none;
}
}
}
}
}
</style>