Skip to content

Commit 36fdd81

Browse files
committed
chore: nuxt demo
1 parent 7763619 commit 36fdd81

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

examples/nuxt/app.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
export default defineAppConfig({
3+
dataLoaders: {
4+
errors(reason) {
5+
console.error('[Data Loaders]', reason)
6+
return false
7+
},
8+
},
9+
})
10+

examples/nuxt/nuxt.config.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
// https://v3.nuxtjs.org/api/configuration/nuxt.config
21
export default defineNuxtConfig({
3-
typescript: {
4-
shim: false,
5-
},
6-
7-
build: {
8-
transpile: [/unplugin-vue-router\/runtime/],
9-
},
10-
11-
app: {
12-
pageTransition: false,
13-
layoutTransition: false,
14-
},
2+
devtools: { enabled: true },
153

164
experimental: {
175
typedPages: true,
186
},
7+
8+
compatibilityDate: '2024-09-10',
199
})

examples/nuxt/pages/users/[id].vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { defineBasicLoader } from 'unplugin-vue-router/data-loaders/basic'
33
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
44
55
export const useUserData = defineBasicLoader(
6+
'users-id',
67
async (route) => {
7-
await delay(300)
8+
console.log('fetching user...')
9+
await delay(1000)
810
const user = {
911
id: route.params.id,
1012
when: Date.now(),
1113
n: Math.round(Math.random() * 10000),
1214
name: 'John Doe',
1315
}
14-
console.log('fetching user:')
1516
console.table(user)
1617
return user
1718
},
@@ -20,12 +21,16 @@ export const useUserData = defineBasicLoader(
2021
</script>
2122

2223
<script setup lang="ts">
24+
defineOptions({
25+
__loaders: [useUserData],
26+
})
2327
const { data: user } = useUserData()
28+
const route = useRoute('users-id')
2429
</script>
2530

2631
<template>
2732
<div>
28-
<h1>User {{ $route.params.id }}</h1>
33+
<h1>User {{ route.params.id }}</h1>
2934
<pre>{{ user }}</pre>
3035
</div>
3136
</template>

examples/nuxt/plugins/uvr.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DataLoaderPlugin, type DataLoaderPluginOptions } from 'unplugin-vue-router/data-loaders'
2+
3+
export default defineNuxtPlugin((nuxtApp) => {
4+
const appConfig = useAppConfig()
5+
6+
nuxtApp.vueApp.use(DataLoaderPlugin, {
7+
router: nuxtApp.vueApp.config.globalProperties.$router,
8+
isSSR: import.meta.server,
9+
...appConfig.dataLoaders,
10+
} satisfies DataLoaderPluginOptions)
11+
})
12+
13+
declare module 'nuxt/schema' {
14+
interface AppConfigInput {
15+
dataLoaders?: Omit<DataLoaderPluginOptions, 'router'>
16+
}
17+
}

examples/nuxt/plugins/vueRouter.ts

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

0 commit comments

Comments
 (0)