[英]Nuxt + Vuex: getter doesn't see state variable
Help me, please.请帮帮我。 My getters in Vuex don't see the state. here is the code: https://codesandbox.io/s/crazy-moon-35fiz?file=/store/user.js
我在 Vuex 中的 getter 看不到 state。这是代码: https://codesandbox.io/s/crazy-moon-35fiz?file=/store/user.js
user.js:用户.js:
export const state = () => ({
user: {
isUserAuthenticated: false,
user_id: null,
}
})
export const getters = {
getUserAuthStatus: (state: any) => {
console.log('state', state) // it's null, why?
return state
}
}
calling my getter at the component:在组件上调用我的 getter:
import { mapGetters } from 'vuex'
...
computed: {
...mapGetters({
isUserAuthenticated: 'user/getUserAuthStatus2',
}),
},
...
State name(user) in the index.js file(/store/index.js) and the name of another file(user.js) coincided. State index.js 文件(/store/index.js) 中的名称(user) 与另一个文件(user.js) 的名称重合。 If you change the name of anyone from them - Everything will work as it should.
如果您更改他们中任何人的名字 - 一切都会正常工作。
I had the same problem but a different solution.我遇到了同样的问题,但解决方案不同。
The plugin vuex-multi-tab-state
was overwriting my actual state with an old one on init.插件
vuex-multi-tab-state
正在用 init 上的旧插件覆盖我实际的 state。
Leaving this here for the next to find.留在这里留待下一次查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.