我正在尝试Gridsome和Vue.js进行相当大的网站转换。网站需要能够从API加载数据。我一直在尝试按照https://gridsome.org/docs/fetching-data/#import-from-apis上的说明进行操作-我粘贴了示例代码。
但是,当我尝试运行Gridsome开发时出现此错误
C:\ projects \ folder \ project> gridsome开发Gridsome v0.6.9
正在初始化插件...正在初始化-0.97s TypeError:actions.addCollection不是函数在api.loadSource(C:\ projects \ VueJS-Research \ my-gridsome-test-VS \ gridsome.server.js:17:36)在process._tickCallback(内部/进程/next_tick.js:68:7)
是Vue.js的新手,我不确定这是怎么回事。我有缺少的包裹吗?
我不得不说,如果遵循文档会导致此类问题,那么我可能不得不得出结论,Gridsome还不够成熟,无法在商业环境中使用,因此我们可能不得不寻找其他地方。
任何帮助,谢谢。
gridsome.server.js文件中的代码:
const axios = require('axios')
module.exports = function (api) {
api.loadSource(async actions => {
const { data } = await axios.get('http://dev.client.local/api/items/suggestitems?family=someCategory')
const collection = actions.addCollection({ typeName: 'clientItems' })
for (const item of data) {
collection.addNode({
label: item.label,
labelNoFamily: item.labelNoFamily,
path: item.path
})
}
})
//api.loadSource(({ addContentType }) => {
// // Use the Data Store API here: https://gridsome.org/docs/data-store-api
//})
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api
})
}