diff --git a/src/App.vue b/src/App.vue index ed395d19db224de7022b3eea4141eb7800f07392..acc37cd4f5d51684ad2414e8ca15f2eeba5ac259 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,10 +11,10 @@ - + - + @@ -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) => {