Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

App.vue

62 lines1.9 KB

1<script setup lang="ts">
2import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
3import { ref } from 'vue'
4import ChatMessage from './ChatMessage.vue'
5​
6const questions = ref<Array<{ id: string; question: string }>>([])
7const currentQuestion = ref('')
8​
9const submitMessage = () => {
10 questions.value = [
11 ...questions.value,
12 { id: crypto.randomUUID(), question: currentQuestion.value },
13 ]
14 currentQuestion.value = ''
16</script>
17​
18<template>
19 <VueQueryDevtools />
20 <div class="flex flex-col h-screen max-w-3xl mx-auto p-4">
21 <h1 class="text-3xl font-bold text-gray-800">TanStack Chat Example</h1>
22 <div class="overflow-y-auto mb-4 space-y-4">
23 <ChatMessage
24 v-for="{ id, question } in questions"
25 :id="id"
26 :key="id"
27 :question="question"
28 />
29 </div>
30​
31 <form class="flex items-center space-x-2" @submit.prevent="submitMessage">
32 <input
33 v-model="currentQuestion"
34 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"
35 placeholder="Type your message..."
36 />
37 <button
38 type="submit"
39 :disabled="!currentQuestion.trim()"
40 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"
41 >
42 <span>Send</span>
43 <svg
44 xmlns="http://www.w3.org/2000/svg"
45 width="24"
46 height="24"
47 viewBox="0 0 24 24"
48 fill="none"
49 stroke="currentColor"
50 stroke-width="2"
51 stroke-linecap="round"
52 stroke-linejoin="round"
53 >
54 <path
55 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"
56 />
57 <path d="m21.854 2.147-10.94 10.939" />
58 </svg>
59 </button>
60 </form>
61 </div>
62</template>