this.$store undefined
时间: 2023-12-12 20:04:52 浏览: 29
this.$store是Vue.js中的一个全局状态管理器,用于在组件之间共享数据。在使用Vue.js和Vuex时,我们可以通过this.$store来访问全局状态管理器。如果出现undefined的情况,可能是因为没有正确地引入Vuex或者没有正确地配置Vuex store。需要检查代码中是否正确引入了Vuex,并且是否正确配置了store。另外,也需要确保在组件中正确地使用了this.$store来访问全局状态管理器。
相关问题
this.$store.state.hasVoted为什么输出undefined
可能的原因有:
1. 在使用`this.$store.state.hasVoted`之前,`hasVoted`属性没有被初始化或赋值,导致其值为`undefined`。
2. `hasVoted`属性被定义在了模块中,但是没有正确地导出或导入,导致无法访问。
3. 在使用`this.$store.state.hasVoted`之前,`this.$store`对象没有被正确地初始化或注入到组件中。
4. `hasVoted`属性被定义为一个getter,但是没有正确地使用`mapGetters`辅助函数进行映射,导致无法访问。
5. 在使用`this.$store.state.hasVoted`之前,可能存在异步操作,导致`hasVoted`属性尚未更新完成,因此其值为`undefined`。
this.$store.getters.getPerms是undefined
你提到的代码 `this.$store.getters.getPerms` 返回了 `undefined`,这种情况可能是由于 `getPerms` 在 Vuex store 的 getters 中未定义引起的。请确保在你的 Vuex store 的 getters 中定义了名为 `getPerms` 的函数,并返回相应的值。另外,还需要确认你是否正确地在组件中调用了该 getter。如果以上方法都没有解决问题,可以提供更多的代码细节,以便我能够更好地帮助你。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)