官方: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) } }
.