Gathering detailed insights and metrics for nuxt-vue-query
Gathering detailed insights and metrics for nuxt-vue-query
Gathering detailed insights and metrics for nuxt-vue-query
Gathering detailed insights and metrics for nuxt-vue-query
npm install nuxt-vue-query
Typescript
Module System
Node Version
NPM Version
41.9
Supply Chain
88.4
Quality
74.5
Maintenance
100
Vulnerability
98.9
License
TypeScript (97.67%)
Vue (2.33%)
Total Downloads
1,166
Last Day
9
Last Week
21
Last Month
42
Last Year
216
1 Stars
22 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Latest Version
0.0.10
Package Id
nuxt-vue-query@0.0.10
Unpacked Size
28.83 kB
Size
7.39 kB
File Count
17
NPM Version
9.5.1
Node Version
19.8.1
Publised On
04 Apr 2023
Cumulative downloads
Total Downloads
Last day
0%
9
Compared to previous day
Last week
90.9%
21
Compared to previous week
Last month
740%
42
Compared to previous month
Last year
-77.3%
216
Compared to previous year
1
useQuery
, useMutation
, etc.useApiGet
, useApiPost
, useApiPut
and useApiDelete
to easy access to Nuxt APIs.query
, post
, parameters
and responses
.useFetch()
under the hood to support SSR. (Why not $fetch
? See)nuxt-vue-query
and @tanstack/vue-query
dependency to your project1npm install --save-dev nuxt-vue-query 2npm install @tanstack/vue-query
nuxt-vue-query
to the modules
section of nuxt.config.ts
. Provide vue-query
configuration.1export default defineNuxtConfig({ 2 modules: ['nuxt-vue-query'], 3 vueQuery: { queryClientConfig: { defaultOptions: { queries: { staleTime: 60000 } } } } 4})
All Tanstack Vue Query features can be used as is:
1const { isLoading, isError, data, error } = useQuery({ queryKey: ['todos'], queryFn: fetchTodoList }) 2 3const { isLoading, isError, error, isSuccess, mutate } = useMutation({ 4 mutationFn: (newTodo) => axios.post('/todos', newTodo), 5}) 6mutate({ id: new Date(), title: 'Do Laundry' })
Add type to server routes. For example /api/item/[id]/[category]
1import type { H3Event } from "h3"; 2 3// Export `Query` and `Body` types. 4export type Query = { language: string }; 5export type Body = { status: string }; 6 7export default eventHandler(async (event: H3Event) => { 8 9});
Zod adds runtime data validation in addition to Type Script's type safety.
1// Zod is optional, but really useful. 2import type { H3Event } from "h3"; 3import { z, parseQueryAs, parseBodyAs, parseParamsAs } from "@sidebase/nuxt-parse"; 4 5const querySchema = z.object({ language: z.string().default("tr") }); 6const bodySchema = z.object({ status: z.string().default("ok") }); 7const parametersSchema = z.object({ id: z.preprocess(Number, z.number()), category: z.string() }).required({ id: true, name: true }); 8 9// Export `Query`, `Body` and `Parameters` types using Zod. 10export type Query = z.infer<typeof querySchema>; 11export type Body = z.infer<typeof bodySchema>; 12export type Parameters = z.infer<typeof parametersSchema>; 13 14export default eventHandler(async (event: H3Event) => { 15 const { language } = parseQueryAs(event, querySchema); 16 const { status } = parseBodyAs(event, bodySchema); 17 const { id, name } = await parseParamsAs(event, parametersSchema); 18});
Query for Nuxt API (get)
1const id = ref(123);
2const category = ref("new-arrivals")
3const query = reactive({ draft: true })
4
5// Pass URL parameters:
6const { isLoading, isError, data, error, queryKey } = await useApiGet(["/api/item/:category/:id", category, id], query, options);
7
8// Without URL parameters:
9const { isLoading, isError, data, error, queryKey } = await useApiGet("/api/prefs", query, options);
Query for Nuxt API (post, put, delete)
1// Pass URL parameters: 2const { isLoading, isError, error, isSuccess, mutate, mutateAsync } = await useApiPost("/api/item/:category/:id", options); 3const data = await mutateAsync([category, id, { color: "red" }]); 4 5// Without URL parameters: 6const { isLoading, isError, error, isSuccess, mutate, mutateAsync } = await useApiPost("/api/prefs", options); 7const data = await mutateAsync({ theme: "dark" }); 8 9const { isLoading, isError, error, isSuccess, mutate, mutateAsync } = await useApiPut("/api/prefs", options); 10const { isLoading, isError, error, isSuccess, mutate, mutateAsync } = await useApiDelete("/api/prefs", options);
No vulnerabilities found.
No security vulnerabilities found.