当前位置: 首页 > news >正文

vuex properties of undefined (reading ‘getters‘)

前言:

        最近打算用vue 写个音乐播放器,在搞 vuex 的时候遇到一个很神奇报错;vuex 姿势练了千百次了,刚开始的时候我一直以为是代码问题,反复检查了带了,依旧报错。 Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'getters')"

 

 除了 mapGetters 中的 方法 都能把数据都正确,连 mapMutations 中的方法都是对的。

按理说 mapMutations 可以,mapGetters 也应该可以才对!

<script>
import { mapGetters, mapMutations } from "vuex";
export default {data() {return {};},computed: {...mapGetters({userInfo: "userInfo",}),userInfo1() {return this.$stroe.state.userInfo;},},mounted() {console.log("this.$stroe:", this.$stroe);console.log("this.$stroe.mapGetters:", this.$stroe.mapGetters);console.log("this.$stroe.getters:", this.$stroe.getters);console.log("this.$stroe.state.userInfo:", this.$stroe.state.userInfo);console.log("this.userInfo1:", this.userInfo1);console.log("this.saveToken:", this.saveToken);console.log("this.userInfo:", this.userInfo);},methods: {...mapMutations({saveToken: "saveToken",}),},
};
</script>输出
store: {…}
this.$stroe: Store {_committing: false, _actions: {…}, _actionSubscribers: Array(0), _mutations: {…}, _wrappedGetters: {…}, …}commit: ƒ boundCommit(type, payload, options)dispatch: ƒ boundDispatch(type, payload)getters: {}strict: false_actionSubscribers: []_actions: {loadStorage: Array(1), cleanStorage: Array(1)}_committing: false_devtools: undefined_makeLocalGettersCache: {}_modules: ModuleCollection {root: Module}_modulesNamespaceMap: {}_mutations: {saveToken: Array(1), updateToken: Array(1), saveUserinfo: Array(1), updateUserInfo: Array(1)}_scope: EffectScope {detached: true, active: true, effects: Array(2), cleanups: Array(0), parent: undefined}_state: {__ob__: Observer}_subscribers: []_wrappedGetters: {userInfo: ƒ, token: ƒ}state: (…)[[Prototype]]: Objectthis.$stroe.mapGetters: undefined
this.$stroe.getters: {}
this.$stroe.state.userInfo: {…}
this.userInfo1: {…}
this.saveToken: ƒ mappedMutation() {var args = [],len = arguments.length;while (len--) args[len] = arguments[len];// Get the commit method from storevar commit = this.$store.commi…

       

解决:

        各种姿势都试了,这次不知道啥情况。代码也检查了;项目重启了, 电脑也重启了。 磨了很长时间 最后试了下 换了个 vuex 版本就然可以了 ! 最后才发现 原来是 引用的 vuex 4.1.0, 版本回退到 3.6.2 就可以了 ,给大家填个坑

http://www.lryc.cn/news/423861.html

相关文章:

  • 再谈表的约束
  • 认识一下测试策略与测试方案
  • Gradle 查看包的依赖关系
  • 虚幻5|给攻击添加特效
  • Delphi包管理与依赖:掌握GetIt与DelphiPI的艺术
  • 如何使用unittest和pytest进行python脚本的单元测试
  • Java中的值传递与引用传递
  • Seaborn库
  • openresty整合modsecurity
  • 结构体structure、共用体union
  • Spring自动注册-<bean>标签和属性解析
  • 【仿RabbitMQ消息队列】基于C++11中packaged_tack异步线程池
  • 免费下载专利
  • CentOS7安装流程步骤详细教程
  • 【大模型从入门到精通17】openAI API 构建和评估大型语言模型(LLM)应用5
  • 苹果手机无iCloud备份下“最近删除”照片的恢复策略
  • Docker搭建Minio容器
  • 【C++】多源BFS问题和拓扑排序
  • CentOS 7 安装详细教程
  • mybatis-plus + springboot 多对多实例
  • SpringBoot日志整合
  • 信创教育:培养未来科技创新的生力军
  • slowfast
  • 怎么调试python脚本
  • Flask获取请求信息
  • Overleaf中放置高分辨率图片的方法
  • 【C语言】动态内存管理(malloc,free,calloc,realloc详解 )
  • 如何寻找数值仿真参数最优解?CFD参数优化详解3来袭
  • 虚拟机macos中构建llvm、clang并配置Xcode
  • Java 中的 @SneakyThrows 注解详解:简化异常处理的利与弊