Open History to see the last commit
1---
2id: quick-start
3title: Quick Start
4ref: docs/framework/react/quick-start.md
5replace: { 'React': 'Vue', 'react-query': 'vue-query' }
6---
7β
8[//]: # 'Example'
9β
10If you're looking for a fully functioning example, please have a look at our [basic codesandbox example](../examples/basic)
11β
12```vue
13<script setup>
14import { useQueryClient, useQuery, useMutation } from '@tanstack/vue-query'
15β
16// Access QueryClient instance
17const queryClient = useQueryClient()
18β
19// Query
20const { isPending, isError, data, error } = useQuery({
21 queryKey: ['todos'],
22 queryFn: getTodos,
23})
24β
25// Mutation
26const mutation = useMutation({
27 mutationFn: postTodo,
28 onSuccess: () => {
29 // Invalidate and refetch
30 queryClient.invalidateQueries({ queryKey: ['todos'] })
31 },
32})
33β
34function onButtonClick() {
35 mutation.mutate({
36 id: Date.now(),
37 title: 'Do Laundry',
38 })
39}
40</script>
41β
42<template>
43 <span v-if="isPending">Loading...</span>
44 <span v-else-if="isError">Error: {{ error.message }}</span>
45 <!-- We can assume by this point that `isSuccess === true` -->
46 <ul v-else>
47 <li v-for="todo in data" :key="todo.id">{{ todo.title }}</li>
48 </ul>
49 <button @click="onButtonClick">Add Todo</button>
50</template>
51```
52β
53[//]: # 'Example'