增加键盘按下事件(Enter)

上级 39fed091
......@@ -11,10 +11,10 @@
<Input v-model="question" type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" placeholder="输入你的问题" />
<Row class="ivu-mt">
<Col>
<Button type="primary" size="large" icon="md-send" :loading="loading" @click="handleSend">发送</Button>
<Button type="primary" size="large" icon="md-send" :loading="loading" @click="handleSend">发送</Button>
</Col>
<Col>
<Button size="large" class="ivu-ml" icon="md-add" :disabled="loading" @click="handleNewChat">新对话</Button>
<Button size="large" class="ivu-ml" icon="md-add" :disabled="loading" @click="handleNewChat">新对话</Button>
</Col>
</Row>
</div>
......@@ -32,7 +32,19 @@ export default {
dialogs: []
}
},
mounted() {
// 增加键盘按下事件
document.addEventListener('keydown', this.handleKeyDown)
},
beforeDestroy() {
document.removeEventListener('keydown', this.handleKeyDown)
},
methods: {
handleKeyDown(event) {
if (event.keyCode === 13) { // keyCode为13表示Enter键
this.handleSend()
}
},
handleSend() {
if (this.loading || this.question === '') return;
this.loading = true;
......@@ -75,7 +87,7 @@ export default {
const source = fetchEventSource(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json'
},
body: JSON.stringify(body),
onopen: (response) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册