增加键盘按下事件(Enter)

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