File tree Expand file tree Collapse file tree 5 files changed +64
-3
lines changed Expand file tree Collapse file tree 5 files changed +64
-3
lines changed Original file line number Diff line number Diff line change
1
+ import type { NuxtApp } from '#app' ;
2
+
3
+ type Dog = {
4
+ breed : string ;
5
+ name : string ;
6
+ age : number ;
7
+ } ;
8
+
9
+ export const useDog = async ( ) => {
10
+ const app = useNuxtApp ( ) ;
11
+
12
+ // fetch Dog data
13
+ await new Promise ( ( res ) => setTimeout ( res , 100 ) ) ;
14
+ const dog : Dog = {
15
+ breed : 'Golden Retriever' ,
16
+ name : 'Buddy' ,
17
+ age : 5 ,
18
+ } ;
19
+
20
+ app . runWithContext ( ( ) => {
21
+ useJsonld ( ( ) => ( {
22
+ '@context' : 'https://schema.org' ,
23
+ '@type' : 'Thing' ,
24
+ name : dog . name ,
25
+ description : `A ${ dog . breed } dog` ,
26
+ } ) ) ;
27
+ } ) ;
28
+
29
+ return {
30
+ data : {
31
+ dog,
32
+ } ,
33
+ } ;
34
+ } ;
Original file line number Diff line number Diff line change 9
9
"start" : " node ./.output/server/index.mjs"
10
10
},
11
11
"dependencies" : {
12
- "nuxt" : " ^3.11.2 "
12
+ "nuxt" : " ^3.12.4 "
13
13
},
14
14
"devDependencies" : {
15
15
"@nuxt/devtools" : " ^0.8.5"
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ <h1 >Context example</h1 >
4
+ <div >
5
+ <pre >{{ JSON.stringify(data.dog, null, 4) }}</pre >
6
+ <nuxt-link to =" /" > Back to list </nuxt-link >
7
+ </div >
8
+ </div >
9
+ </template >
10
+
11
+ <script lang="ts" setup>
12
+ import { useDog } from ' @/composables/dog' ;
13
+ const { data } = await useDog ();
14
+ </script >
15
+
16
+ <style scoped>
17
+ pre {
18
+ display : block ;
19
+ margin : 10px auto ;
20
+ max-width : 300px ;
21
+ padding : 12px ;
22
+ text-align : left ;
23
+ background-color : gainsboro ;
24
+ border-radius : 4px ;
25
+ }
26
+ </style >
Original file line number Diff line number Diff line change 11
11
<li ><nuxt-link :to =" { name: 'static' }" >Static JSON</nuxt-link ></li >
12
12
<li ><nuxt-link :to =" { name: 'option' }" >Options API</nuxt-link ></li >
13
13
<li ><nuxt-link :to =" { name: 'composable-options' }" >Composable API Options</nuxt-link ></li >
14
+ <li ><nuxt-link :to =" { name: 'context' }" >Context</nuxt-link ></li >
14
15
</ul >
15
16
</div >
16
17
</template >
17
18
18
19
<script lang="ts">
19
- import { WithContext , ItemList } from ' schema-dts' ;
20
+ import type { WithContext , ItemList } from ' schema-dts' ;
20
21
21
22
export default defineComponent ({
22
23
setup() {
Original file line number Diff line number Diff line change @@ -7553,7 +7553,7 @@ nuxi@^3.15.0:
7553
7553
resolved "https://registry.yarnpkg.com/nuxi/-/nuxi-3.15.0.tgz#ed54923ca46727c6e7df10495143db340d9791c9"
7554
7554
integrity sha512-ZVu45nuDrdb7nzKW2kLGY/N1vvFYLLbUVX6gUYw4BApKGGu4+GktTR5o48dGVgMYX9A8chaugl7TL9ZYmwC9Mg==
7555
7555
7556
- nuxt@^3.11.2 :
7556
+ nuxt@^3.11.2, nuxt@^3.12.4 :
7557
7557
version "3.14.1592"
7558
7558
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-3.14.1592.tgz#0f94132b7e0ffe9087b37392f295e2c7d5d05ee3"
7559
7559
integrity sha512-roWAQH4Mb6WY72cNos+YVw0DgTCNAhNygiAMCedM7hbX6ESTR2n3VH7tU0yIWDPe/hfFdii4M4wWTTNHOtS44g==
You can’t perform that action at this time.
0 commit comments