Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianOsipiuk committed May 19, 2022
1 parent 64b4719 commit 33acbf6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/nuxt-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@nuxtjs/composition-api": "^0.28.0",
"nuxt": "^2.0.0",
"vue-query": "^1.5.1"
"vue-query": ">=1.0.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/nuxt-simple/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default defineComponent({
const { refetch, data, suspense } = useQuery("todos", fetcher, {
// If you do not want data to be refetched on the client, set a staleTime to high enough time
staleTime: 1000,
staleTime: 5000,
});
onServerPrefetch(async () => {
Expand Down
6 changes: 3 additions & 3 deletions examples/nuxt-simple/plugins/vue-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { VueQueryPlugin, QueryClient, hydrate } from "vue-query";
export default (context) => {
// Modify your Vue Query global settings here
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 1000 } },
defaultOptions: { queries: { staleTime: 5000 } },
});
const options = { queryClient };

Vue.use(VueQueryPlugin, options);

if (process.client) {
if (context.nuxtState && context.nuxtState["vue-query"]) {
hydrate(queryClient, context.nuxtState["vue-query"]);
if (context.nuxtState && context.nuxtState["vueQueryState"]) {
hydrate(queryClient, context.nuxtState["vueQueryState"]);
}
}
};
24 changes: 4 additions & 20 deletions examples/nuxt3-simple/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@
<div>{{ data }}</div>
</template>

<script lang="ts">
<script setup lang="ts">
import { useQuery } from "vue-query";
import { defineComponent, onServerPrefetch } from "vue";
interface Post {
userId: number;
id: number;
title: string;
body: string;
}
const fetcher = async (): Promise<Post[]> =>
const fetcher = async () =>
await fetch("https://jsonplaceholder.typicode.com/posts").then((response) =>
response.json()
);
export default defineComponent({
setup() {
const { data, suspense } = useQuery("test", fetcher);
onServerPrefetch(async () => {
await suspense();
});
const { data, suspense } = useQuery("test", fetcher);
return { data };
},
});
await suspense();
</script>
2 changes: 1 addition & 1 deletion examples/nuxt3-simple/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtConfig } from "nuxt3";
import { defineNuxtConfig } from "nuxt";

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({});
2 changes: 1 addition & 1 deletion examples/nuxt3-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"nuxt3": "latest"
"nuxt": "npm:nuxt3@latest"
},
"dependencies": {
"vue-query": ">=1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/nuxt3-simple/plugins/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
export default (nuxt) => {
// Modify your Vue Query global settings here
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 1000 } },
defaultOptions: { queries: { staleTime: 5000 } },
});
const options: VueQueryPluginOptions = { queryClient };

Expand Down

1 comment on commit 33acbf6

@vercel
Copy link

@vercel vercel bot commented on 33acbf6 May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vue-query – ./

vue-query-damianosipiuk.vercel.app
vue-query.vercel.app
vue-query-git-main-damianosipiuk.vercel.app

Please sign in to comment.