File tree Expand file tree Collapse file tree 5 files changed +38
-21
lines changed Expand file tree Collapse file tree 5 files changed +38
-21
lines changed Original file line number Diff line number Diff line change
1
+
2
+ export default defineAppConfig ( {
3
+ dataLoaders : {
4
+ errors ( reason ) {
5
+ console . error ( '[Data Loaders]' , reason )
6
+ return false
7
+ } ,
8
+ } ,
9
+ } )
10
+
Original file line number Diff line number Diff line change 1
- // https://v3.nuxtjs.org/api/configuration/nuxt.config
2
1
export default defineNuxtConfig ( {
3
- typescript : {
4
- shim : false ,
5
- } ,
6
-
7
- build : {
8
- transpile : [ / u n p l u g i n - v u e - r o u t e r \/ r u n t i m e / ] ,
9
- } ,
10
-
11
- app : {
12
- pageTransition : false ,
13
- layoutTransition : false ,
14
- } ,
2
+ devtools : { enabled : true } ,
15
3
16
4
experimental : {
17
5
typedPages : true ,
18
6
} ,
7
+
8
+ compatibilityDate : '2024-09-10' ,
19
9
} )
Original file line number Diff line number Diff line change @@ -3,15 +3,16 @@ import { defineBasicLoader } from 'unplugin-vue-router/data-loaders/basic'
3
3
const delay = (ms : number ) => new Promise ((resolve ) => setTimeout (resolve , ms ))
4
4
5
5
export const useUserData = defineBasicLoader (
6
+ ' users-id' ,
6
7
async (route ) => {
7
- await delay (300 )
8
+ console .log (' fetching user...' )
9
+ await delay (1000 )
8
10
const user = {
9
11
id: route .params .id ,
10
12
when: Date .now (),
11
13
n: Math .round (Math .random () * 10000 ),
12
14
name: ' John Doe' ,
13
15
}
14
- console .log (' fetching user:' )
15
16
console .table (user )
16
17
return user
17
18
},
@@ -20,12 +21,16 @@ export const useUserData = defineBasicLoader(
20
21
</script >
21
22
22
23
<script setup lang="ts">
24
+ defineOptions ({
25
+ __loaders: [useUserData ],
26
+ })
23
27
const { data : user } = useUserData ()
28
+ const route = useRoute (' users-id' )
24
29
</script >
25
30
26
31
<template >
27
32
<div >
28
- <h1 >User {{ $ route.params.id }}</h1 >
33
+ <h1 >User {{ route.params.id }}</h1 >
29
34
<pre >{{ user }}</pre >
30
35
</div >
31
36
</template >
Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments