Open History to see the last commit
1<script setup lang="ts">
2import { ref } from 'vue'
3import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
4β
5import ChatMessage from './ChatMessage.vue'
6β
7const questions = ref<Array<{ id: string; question: string }>>([])
8const currentQuestion = ref('')
9β
10const submitMessage = () => {
11 questions.value = [
12 ...questions.value,
13 { id: crypto.randomUUID(), question: currentQuestion.value },
14 ]
15 currentQuestion.value = ''
16}
17</script>
18β
19<template>
20 <VueQueryDevtools />
21 <div class="flex flex-col h-screen max-w-3xl mx-auto p-4">
22 <h1 class="text-3xl font-bold text-gray-800">TanStack Chat Example</h1>
23 <div class="overflow-y-auto mb-4 space-y-4">
24 <ChatMessage
25 v-for="{ id, question } in questions"
26 :id="id"
27 :key="id"
28 :question="question"
29 />
30 </div>
31β
32 <form class="flex items-center space-x-2" @submit.prevent="submitMessage">
33 <input
34 v-model="currentQuestion"
35 class="flex-1 p-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-100"
36 placeholder="Type your message..."
37 />
38 <button
39 type="submit"
40 :disabled="!currentQuestion.trim()"
41 class="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold px-4 py-2 rounded-2xl shadow-md transition"
42 >
43 <span>Send</span>
44 <svg
45 xmlns="http://www.w3.org/2000/svg"
46 width="24"
47 height="24"
48 viewBox="0 0 24 24"
49 fill="none"
50 stroke="currentColor"
51 stroke-width="2"
52 stroke-linecap="round"
53 stroke-linejoin="round"
54 >
55 <path
56 d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"
57 />
58 <path d="m21.854 2.147-10.94 10.939" />
59 </svg>
60 </button>
61 </form>
62 </div>
63</template>