diff --git a/src/views/Chat/index.vue b/src/views/Chat/index.vue index 03e9a55..3fed308 100644 --- a/src/views/Chat/index.vue +++ b/src/views/Chat/index.vue @@ -15,7 +15,7 @@ const scrollRef = ref() const ms = useMessage() -const value = ref('') +const prompt = ref('') const loading = ref(false) @@ -45,17 +45,19 @@ function handleEnter(event: KeyboardEvent) { } async function handleSubmit() { - if (!value.value) { + const message = prompt.value.trim() + + if (!message || !message.length) { ms.warning('Please enter a message') return } - addMessage(value.value, true) + addMessage(message, true) + prompt.value = '' try { loading.value = true - const { text } = await fetchChatAPI(value.value) - value.value = '' + const { text } = await fetchChatAPI(message) addMessage(text, false) } catch (error: any) { @@ -104,7 +106,7 @@ function addMessage(message: string, reversal = false) {