vuex 需要 Vue.prototype.$store 吗?

时间:2020-12-23 12:47:46   收藏:0   阅读:258

 

官方:https://vuex.vuejs.org/zh/guide/

有说明:

为了在 Vue 组件中访问 this.$store property,你需要为 Vue 实例提供创建好的 store。Vuex 提供了一个从根组件向所有子组件,以 store 选项的方式“注入”该 store 的机制:

所以已经注入,不需要用  Vue.prototype.$store = store 重复挂载

直接使用 this.$store

methods: {
  increment() {
    this.$store.commit(increment)
    console.log(this.$store.state.count)
  }
}

 

原文:https://www.cnblogs.com/xiangsj/p/14177858.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!