Skip to content

Commit d62849d

Browse files
docs: update examples (#24)
* docs: simple example * docs: base example
1 parent 2389bb1 commit d62849d

27 files changed

+287
-27
lines changed

.codesandbox/ci.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"packages": ["./"],
3-
"sandboxes": ["/examples/multi-page", "/examples/basic-vue-2.x"],
3+
"sandboxes": ["/examples/base", "/examples/basic-vue-2.x"],
44
"node": "14"
55
}

docs/_sidebar.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
- Examples
99

10-
- [Basic](examples/basic.md)
10+
- [Simple](examples/simple.md)
11+
- [Basic](examples/base.md)
1112
- [Multi Page](examples/multi-page.md)
1213
- [Suspense](examples/suspense.md)
1314
- [Vue 2.x](examples/vue-2.x.md)

docs/examples/base.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- [Open in Codesandbox](https://codesandbox.io/s/github/DamianOsipiuk/vue-query/tree/main/examples/base)
2+
- [View Source](https://github.com/DamianOsipiuk/vue-query/tree/main/examples/base)
3+
4+
<iframe src="https://codesandbox.io/embed/github/DamianOsipiuk/vue-query/tree/main/examples/base?hidenavigation=1&view=preview&codemirror=1"
5+
style="height:700px; border:0; overflow:hidden;"
6+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
7+
></iframe>

docs/examples/basic.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/examples/simple.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- [Open in Codesandbox](https://codesandbox.io/s/github/DamianOsipiuk/vue-query/tree/main/examples/simple)
2+
- [View Source](https://github.com/DamianOsipiuk/vue-query/tree/main/examples/simple)
3+
4+
<iframe src="https://codesandbox.io/embed/github/DamianOsipiuk/vue-query/tree/main/examples/simple?hidenavigation=1&view=preview&codemirror=1"
5+
style="height:700px; border:0; overflow:hidden;"
6+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
7+
></iframe>

examples/basic/.gitignore renamed to examples/base/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
dist
44
dist-ssr
55
*.local
6+
package-lock.json
File renamed without changes.

examples/basic/index.html renamed to examples/base/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Vue-query example</title>
6+
<title>Vue Query Example</title>
77
</head>
88
<body>
99
<div id="app"></div>
File renamed without changes.

examples/base/src/App.vue

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script lang="ts">
2+
import { ref } from "vue";
3+
import { defineComponent } from "vue";
4+
import { useQueryProvider } from "vue-query";
5+
import { VueQueryDevTools } from "vue-query/devtools";
6+
7+
import Posts from "./Posts.vue";
8+
import Post from "./Post.vue";
9+
10+
export default defineComponent({
11+
name: "App",
12+
components: { Posts, Post, VueQueryDevTools },
13+
setup() {
14+
useQueryProvider();
15+
16+
const visitedPosts = ref(new Set());
17+
const isVisited = (id: number) => visitedPosts.value.has(id);
18+
19+
const postId = ref(-1);
20+
const setPostId = (id: number) => {
21+
visitedPosts.value.add(id);
22+
postId.value = id;
23+
};
24+
25+
return {
26+
isVisited,
27+
postId,
28+
setPostId,
29+
};
30+
},
31+
});
32+
</script>
33+
34+
<template>
35+
<h1>Vue Query - Basic</h1>
36+
<p>
37+
As you visit the posts below, you will notice them in a loading state the
38+
first time you load them. However, after you return to this list and click
39+
on any posts you have already visited again, you will see them load
40+
instantly and background refresh right before your eyes!
41+
<strong>
42+
(You may need to throttle your network speed to simulate longer loading
43+
sequences)
44+
</strong>
45+
</p>
46+
<Post
47+
v-if="postId > -1"
48+
:postId="postId"
49+
:style="{}"
50+
@setPostId="setPostId"
51+
/>
52+
<Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
53+
<VueQueryDevTools :initialIsOpen="true" />
54+
</template>

0 commit comments

Comments
 (0)