【发布时间】:2019-08-06 22:32:21
【问题描述】:
我正在尝试使用我的第一个 Headless CMS,并且我已经尝试了 Prismic.io 和 Contentful。
例如,这是来自 Contentful 指南的代码:
asyncData({ env }) {
return Promise.all([
// fetch the owner of the blog
client.getEntries({
'sys.id': env.CTF_PERSON_ID
}),
// fetch all blog posts sorted by creation date
client.getEntries({
content_type: env.CTF_BLOG_POST_TYPE_ID,
order: '-sys.createdAt'
})
])
.then(([entries, posts]) => {
// return data that should be available
// in the template
return {
person: entries.items[0],
posts: posts.items
}
})
.catch(console.error)
}
这很好用,我可以在
中获取我的博客文章 <article v-for="post in posts" :key="post">
<h2>{{ post.fields.title }}</h2>
<p>{{ post.fields.content }}</p>
</article>
但是,如果我使用 Nuxt 生成静态页面,我知道该页面在活动时仍会从 Contentful 加载最新版本的内容,而它只是在生成时保留在页面上获取的静态内容。
我错过了这里的重点吗?
谢谢
【问题讨论】:
标签: vue.js contentful nuxt.js headless-cms