【问题标题】:Gridsome doesn't refresh data after changes in APIAPI 更改后 Gridsome 不刷新数据
【发布时间】:2021-10-15 17:07:01
【问题描述】:

我从 Strapi Api 作为 Collection 获取数据,它可以工作,但如果我在 Strapi 中进行更改,Gridsome 中的数据不会更改,我必须重新启动 Gridsome 服务器才能获取新信息。

在本地开发中运行 Api 和 Gridsome

我已经检查了 strpi 是否正常工作,而 graphql 没有得到新数据。

我的代码:

gridsome.server.js

const axios = require('axios')

api.loadSource(async actions => {
const { data } = await axios.get('http://localhost:1337/events')

const collection = actions.addCollection({
   typeName: 'Event',
   path: 'event/:id'
})

 for (const event of data) {
 collection.addNode({
 id: event.id,
 title: event.title,
 description: event.description,
 price: event.price,
 date: event.date,
 location: event.location,
 duration: event.duration,
 coverName: event.cover.hash,
 coverThumbNail: event.cover.formats.thumbnail.url,
 coverMedium: event.cover.formats.medium.url,
 coverImage: event.cover.formats.large.url,
 category: event.categories,
 path: '/events/'+event.id
 })
}
})

我的 index.vue

<page-query> query { events: allEvent{ edges{ node { id title description price date location duration coverName coverThumbNail coverMedium coverImage category { id } } } } } </page-query>

 <script>
     export default {
          data: () => ({
          events: []
         }),
          mounted() {
         this.events = this.$page.events.edges
          },
         }

感谢您的宝贵时间

【问题讨论】:

    标签: api vue.js asynchronous strapi gridsome


    【解决方案1】:

    来自strapi.io 上的文档 https://strapi.io/documentation/developer-docs/latest/developer-resources/content-api/integrations/gridsome.html#configure-gridsome

    Gridsome is a Static Site Generator (opens new window)and will fetch your content from Strapi at build time.

    基本上,这意味着 Gridsome 的 GraphQL 在构建中“填充”了来自 ​​Strapi 的数据,要获得新帖子,您应该重新生成页面。

    如果您不想在每次添加帖子时手动部署您的网站,您应该检查 Strapi 的 webhooks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 2013-01-05
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多