问题描述
我有一个nuxt.js应用程序,其中使用了fetch()挂钩从API提取数据,如下所示:
async fetch() {
await this.$store.dispatch('articles/getArticlesDetails',this.$route.params.id)
}
并且我想在客户端使用API返回的数据,并尝试将其装入安装,并且在装入中未定义。
还有没有其他有效的方法来获取和使用数据,以便进一步在客户端进行API调用。
解决方法
我假设您的Vuex Action对State数据进行了突变:
store.js
export const state = () => ({
dataFromAPI: []
})
然后,您应该能够从_id.vue
中检索更新后的状态:
export default {
computed: {
apiData() {
return this.$store.state.dataFromAPI
}
}
}