我正在使用storyblok-nuxt模块。我将其插入nuxt.cofig.js中,当我在asyncData方法中直接调用它时,它在页面中工作得很好:
asyncData({ app }) {
return app.$storyapi.get("cdn/stories/articles", {
version: "draft"
})为了叫它从vuex,我进口它:
import storyapi from 'storyapi'但是Nuxt给了我一个错误:
Cannot find module 'storyapi'我可以使用这个模块在vuex,如果是-什么是解决方案?
发布于 2020-05-17 15:46:09
在Nuxt中使用storyapi非常容易。在您的asyncData中,您可以分派您的操作如下:
asyncData ({ store }) {
store.dispatch('loadSettings', {version: "draft"})
}在您的商店操作中,您可以直接使用this.$storyapi。没有必要进口任何东西。不要为你照顾一切:
export const actions = {
loadSettings({commit}, context) {
return this.$storyapi.get("cdn/stories/articles", {
version: context.version
}).then((res) => {
// execute your action and set data
commit('setSettings', res.data)
})
}
}有关详细信息,请访问:
https://stackoverflow.com/questions/61854104
复制相似问题