1
1
# ⚗️ Vue Query Nuxt
2
2
3
3
[ ![ CI] ( https://github.com/Hebilicious/vue-query-nuxt/actions/workflows/ci.yaml/badge.svg )] ( https://github.com/Hebilicious/vue-query-nuxt/actions/workflows/ci.yaml )
4
- [ ![ npm version] ( https://badge.fury.io/js/@hebilicious%2Fvue -query-nuxt.svg )] ( https://badge.fury.io/js/@hebilicious%2Fvue -query-nuxt )
4
+ [ ![ npm version] ( https://badge.fury.io/js/@hebilicious%20vue -query-nuxt.svg )] ( https://badge.fury.io/js/@hebilicious%20vue -query-nuxt )
5
5
[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
6
6
7
7
🚀 Welcome to __ Vue Query Nuxt__ !
8
8
9
9
This Nuxt Module automatically installs and configure Vue Query for your Nuxt application.
10
10
It has 0 config out-of-the box and extremely lightweight.
11
11
12
- ## ⚠️ Disclaimer
12
+ ## Features
13
13
14
- _ 🧪 This module is in active development._
14
+ - 0 config out-of-the box
15
+ - All configurations options available
16
+ - Auto Imports for Vue Query composables
15
17
16
18
Refer to the [ Vue Query documentation] ( https://tanstack.com/query/latest/docs/vue/quick-start ) for more information about Vue Query.
17
19
18
- ## 📦 Installation
20
+ ## 📦 How to use
19
21
20
-
21
- 1 . Use npm, pnpm or yarn to install the dependencies.
22
+ ### 1. Use npm, pnpm or yarn to install the dependencies.
22
23
23
24
``` bash
25
+ # npm
24
26
npm i @hebilicious/vue-query-nuxt @tanstack/vue-query
25
- ```
26
-
27
- ``` bash
27
+ # pnpm
28
28
pnpm i @hebilicious/vue-query-nuxt @tanstack/vue-query
29
+ # yarn
30
+ yarn add @hebilicious/vue-query-nuxt @tanstack/vue-query
29
31
```
30
32
31
- ``` bash
32
- yarn i @hebilicious/vue-query-nuxt @tanstack/vue-query
33
- ```
33
+ ### 2. Add the modules to your Nuxt modules
34
34
35
- 2 . Add the modules to your Nuxt modules
35
+ In ` nuxt.config.ts ` :
36
36
37
37
``` ts
38
- // In nuxt.config.ts
39
38
export default defineNuxtConfig ({
40
39
modules: [" @hebilicious/vue-query-nuxt" ]
41
40
})
42
41
```
43
42
44
- 3 . Use right away
43
+ ### 3. Use right away
45
44
46
- ``` html
47
- <script setup >
48
- import { useQueryClient , useQuery , useMutation } from ' @tanstack/vue-query'
45
+ In a vue component :
49
46
47
+ ``` html
48
+ <script setup lang =" ts" >
50
49
// Access QueryClient instance
51
50
const queryClient = useQueryClient ()
52
51
@@ -84,28 +83,38 @@ function onButtonClick() {
84
83
</template >
85
84
```
86
85
87
- 4 . Advanced configuration
86
+ ### 4. Advanced configuration
88
87
89
88
You can specify the options under the vueQuery key in your nuxt.config.ts file.
90
89
Everything is typed.
91
90
91
+ In ` nuxt.config.ts ` :
92
+
92
93
``` ts
93
- // In nuxt.config.ts
94
94
export default defineNuxtConfig ({
95
95
modules: [" @hebilicious/vue-query-nuxt" ],
96
96
vueQuery: {
97
- stateKey: " vue-query-nuxt" ,
97
+ // useState key used by nuxt for the vue query state.
98
+ stateKey: " vue-query-nuxt" , // default
99
+ // If you only want to import some functions, specify them here.
100
+ // You can pass false or an empty array to disable this feature.
101
+ // default: ["useQuery", "useQueries", "useInfiniteQuery", "useMutation", "useIsFetching", "useIsMutating", "useQueryClient"]
102
+ autoImports: [" useQuery" ],
103
+ // Pass the vue query client options here ...
98
104
queryClientOptions: {
99
105
defaultOptions: { queries: { staleTime: 5000 } } // default
100
106
},
107
+ // Pass the vue query plugin options here ....
101
108
vueQueryPluginOptions: {}
102
109
}
103
110
})
104
111
```
112
+
105
113
If you need to modify the plugin that installs vue query, you can create a ` vue-query.config.ts ` file at the root of your project.
106
114
115
+ In ` vue-query.config.ts ` :
116
+
107
117
``` ts
108
- // vue-query.config.ts
109
118
import { library } from " @example/libray"
110
119
111
120
export default defineVueQueryPluginCallback ((vueQueryOptions ) => {
@@ -114,7 +123,7 @@ export default defineVueQueryPluginCallback((vueQueryOptions) => {
114
123
})
115
124
```
116
125
117
- This callback will be run * directly * after the Vue Query plugin is installed, so you can use it to ` provide ` something.
126
+ This callback will be run _ directly _ after the Vue Query plugin is installed, so you can use it to ` provide ` something.
118
127
This can be useful if you want to configure something that needs the ` queryClient ` or you want to provide a library in the same plugin.
119
128
120
129
## 📦 Contributing
0 commit comments