Skip to content

Commit

Permalink
docs: add simple example for document homepage (#6857)
Browse files Browse the repository at this point in the history
* docs: add simple example for document homepage

* chore: run prettier
  • Loading branch information
Mini-ghost committed Feb 12, 2024
1 parent 3b6c32a commit 5f1b505
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/vue/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.DS_Store
dist
dist-ssr
*.local

package-lock.json
yarn.lock
pnpm-lock.yaml
6 changes: 6 additions & 0 deletions examples/vue/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Basic example

To run this example:

- `npm install` or `yarn` or `pnpm i`
- `npm run dev` or `yarn dev` or `pnpm dev`
12 changes: 12 additions & 0 deletions examples/vue/simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TanStack Query Vue Simple Example App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/vue/simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@tanstack/query-example-vue-simple",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/vue-query": "^5.18.1",
"@tanstack/vue-query-devtools": "^5.18.1",
"vue": "^3.3.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.2",
"typescript": "5.2.2",
"vite": "^5.0.10"
}
}
43 changes: 43 additions & 0 deletions examples/vue/simple/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { useQuery } from '@tanstack/vue-query'
import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
export default defineComponent({
name: 'App',
components: { VueQueryDevtools },
setup() {
const { data, error, isFetching, isPending } = useQuery({
queryKey: ['repoData'],
async queryFn() {
return await fetch('https://api.github.com/repos/Tanstack/query').then(
(response) => response.json(),
)
},
})
return {
data,
error,
isFetching,
isPending,
}
},
})
</script>

<template>
<template v-if="isPending"> Loading... </template>
<template v-else-if="error">
'An error has occurred: {{ error.message }}
</template>
<template v-else>
<h1>{{ data.name }}</h1>
<p>{{ data.description }}</p>
<strong>👀 {{ data.subscribers_count }}</strong>
<strong>✨ {{ data.stargazers_count }}</strong>
<strong>🍴 {{ data.forks_count }}</strong>
<div>{{ isFetching ? 'Updating...' : '' }}</div>
</template>
<VueQueryDevtools />
</template>
6 changes: 6 additions & 0 deletions examples/vue/simple/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createApp } from 'vue'
import { VueQueryPlugin } from '@tanstack/vue-query'

import App from './App.vue'

createApp(App).use(VueQueryPlugin).mount('#app')
5 changes: 5 additions & 0 deletions examples/vue/simple/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
6 changes: 6 additions & 0 deletions examples/vue/simple/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Post {
userId: number
id: number
title: string
body: string
}
15 changes: 15 additions & 0 deletions examples/vue/simple/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"types": ["vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"]
}
9 changes: 9 additions & 0 deletions examples/vue/simple/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
plugins: [vue()],
optimizeDeps: {
exclude: ['@tanstack/vue-query', 'vue-demi'],
},
})
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f1b505

Please sign in to comment.