如何在组件内部使用@nuxt/content?
How to use @nuxt/content inside Component?
我正在尝试在一个组件内使用 nuxt-contnt,它在带有 asyncData 的页面中运行良好,但在组件内不起作用
这很好用:
export default {
async asyncData({ $content }) {
const page = await $content('hello').fetch()
return {
page,
}
},
}
但这不起作用:
export default {
data() {
return {
content: [],
}
},
async fetch({ $content }) {
this.content = await $content('hello').fetch()
},
}
fetch
没有任何参数但可以访问this
,所以应该是
async fetch() {
this.content = await this.$content('hello').fetch()
}
我正在尝试在一个组件内使用 nuxt-contnt,它在带有 asyncData 的页面中运行良好,但在组件内不起作用
这很好用:
export default {
async asyncData({ $content }) {
const page = await $content('hello').fetch()
return {
page,
}
},
}
但这不起作用:
export default {
data() {
return {
content: [],
}
},
async fetch({ $content }) {
this.content = await $content('hello').fetch()
},
}
fetch
没有任何参数但可以访问this
,所以应该是
async fetch() {
this.content = await this.$content('hello').fetch()
}