nuxt.js - Nuxt.js 服务器端渲染:启动服务器后数据未更新
问题描述
我遇到了 Nuxt.js 和 Apollo 的问题,没有使用我的 API 源中的最新内容更新我的页面内容。服务器在启动时会“卡在”版本上,除非我重新启动服务器,否则数据不会更新。我在 Github 上搜索过任何类似的问题,甚至在这里也找不到任何东西。
我正在"@nuxtjs/apollo": "^4.0.1-rc.5"
使用"nuxt": "^2.14.12"
.
使用nuxt dev
模式时,我没有问题,我的页面数据被正确获取,如果我在我的 API 上更改它的一些数据,然后重新加载页面,数据就会更新。
Nuxt 设置为以服务器为目标,因此它不会构建静态文件。
当我在 SSR 中时,nuxt build && nuxt start
我的页面最初会显示正确的数据,所以 SSR 似乎可以工作。但是,如果我编辑我的 API 数据然后重新加载页面,我不会更新页面内容,而是更新我运行时的版本nuxt start
。
如果我停止并重新启动应用程序,然后重新加载页面,我就会显示正确的更新数据。我觉得这可能是一个与缓存相关的问题。
这是我加载到 Nuxt 中的 apollo 配置:
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'
import introspectionQueryResultData from './graphql.schema.json'
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData
})
const cache = InMemoryCache({ fragmentMatcher })
export default function (ctx) {
return {
httpEndpoint: MY_ENDPOINT,
cache
}
}
我需要 Fragment Matcher 才能使用 GraphQL 片段并使用 codegen 生成类型,我的代码库在 Typescript 中。这在开发模式下就像一个魅力,但可能是它在 SSR 中不起作用的原因,即使我找不到原因。
在我的 Vue 组件上呈现我的页面,这是一个示例配置:
apollo: {
page: {
prefetch: true,
query: queryPage, // imported GraphQL query with .gql file
variables() {
return {
id: 2
}
}
}
}
我不明白为什么我的服务器在启动后没有重新获取数据。我尝试在 Nuxt 生成的服务器文件中进行调试但没有成功。
如何让我的页面在加载时获取数据,而无需在每次更新我的 API 内容后重新启动应用程序?
解决方案
对于任何面临类似问题的人。降级为"@nuxtjs/apollo": "4.0.1-rc.1"
作品。
推荐阅读
- networking - Kubernetes 服务的间歇性超时
- php - 如何使用 PHP 从一个 csv 文件中删除不在另一个文件中的行?
- python - 如何在张量流数据集中映射numpy数组
- arrays - 循环遍历数组并写入错误消息
- python - 使用 python sqlalchemy 使用 WITH 语句执行原始查询
- javascript - 当作为子组件添加时,以不同的方式对本机组件渲染做出反应
- spring-boot - Kafka 消费者的 Spring Boot/Jhipster 集成测试构建失败
- sql-server - 之前用?分配查询结果?
- python - Tensorflow/Keras Conv2D 层中的输入形状错误
- qt - qt.qpa.plugin:无法在“”中加载 Qt 平台插件“xcb”,即使它已找到