风之源
风之源
  • 发布:2022-07-07 13:19
  • 更新:2023-01-02 23:41
  • 阅读:2596

Property "$store" was accessed during render but is not defined on instance.

分类:nvue

在组件里的computed里用了this.$store,提示“Property "$store" was accessed during render but is not defined on instance.”,我关闭了fast启动模式和纯nvue也不行。同样的代码编译到微信小程序就正常。

2022-07-07 13:19 负责人:无 分享
已邀请:
放牛郎

放牛郎

你如果是vue3模式的话 在computed 调用状态管理的变量 会提示这个问题 我发现在onload 或 created生命周期中先调用一次this.$store.xxx 计算属性当中的调用就不会报警告信息 我是使用mapState 然后再在computed 里调用了这里面的变量 提示的 我在生命周期中先行调用了 就不会提示

放牛郎

放牛郎

vue3模式 假设里在 computed 里 mapState(['test']) 然后在computed xxx(){return this.test} 就会提示在渲染中引用但...未定义 此警告信息 可以通过 onload生命周期 或者created生命周期 里调用一次 this.test 就不会提示警告信息 例如在created生命周期中 console.log(this.test)

要回复问题请先登录注册