我正在尝试使用我的第一个Headless CMS,并且尝试了Prismic.io和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中加载内容的最新版本,而只是保留生成时在页面上获取的静态内容。
我在这里错过要点吗?
谢谢
答案 0 :(得分:0)
您发现的是正确的。当发生新的导航时,当前版本的Nuxt向内容API发出请求。 Afaik计划在构建期间将数据写入磁盘(例如Gatsby这样做),但尚未实现。
我个人就是在这个技术堆栈上运行我的私人博客,并且有一个很小的时间窗口,其中静态页面和动态加载的部分不同。到目前为止,对我来说这不是什么问题。我可以理解,但这可能会引起麻烦。