From bfbfeff311eadd6ea4891f8ad5458cf4a84d7717 Mon Sep 17 00:00:00 2001 From: 6448dfb631ba9538b4877fd6 <6448dfb631ba9538b4877fd6@devide> Date: Mon, 29 May 2023 09:45:20 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=AE=E7=9B=98=E6=8C=89?= =?UTF-8?q?=E4=B8=8B=E4=BA=8B=E4=BB=B6=EF=BC=88Enter=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index ed395d1..acc37cd 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) => { -- GitLab