我发现了一些关于我最后解释过的错误;
构件码
async fetch(){ await this.$store.dispatch('bots/getBots') },
computed: { ...mapState('bots', ['bots']) },存储码
export const state = () => {
return {
bots: []
}
}
export const mutations = {
UPDATE_BOTS(state, bots) {
state.bots = bots
}
}
export const actions = {
getBots({commit}) {
this.$axios.$get('url', {headers: {uid: '12345'}})
.then(res => {
commit('UPDATE_BOTS',res.robots)
})
.catch(e => {
console.log(e)
})
}
}问题:当通过nuxt链接数据在页面之间移动时,完美地加载数据,但是当我重新加载页面bots状态是空的.
发现的问题:我使用nuxt-auth和我有一个插件来检查axios请求的状态,如果是401未经授权的用户,如果他是loggedIn,那么状态未定义的错误来自这里,但是我注释了插件代码,我从nuxt-auth得到了其他错误,导致了这个问题,所以我在其他问题中将这个问题联系起来,你可以在这里看到它:Nuxt-Auth Bug: Looks for autherization in any get request that has headers config。
发布于 2022-03-05 13:02:48
这是人们所期待的行为。Vuex状态保存在内存中,当您重新加载页面时,它会被清除。
发布于 2022-03-05 19:39:56
而不是这种状态
export const state = () => {
return {
bots: []
}
}尝尝这个
export const state = () => ({
bots: []
})https://stackoverflow.com/questions/71360880
复制相似问题