【发布时间】: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