import Vue from 'vue'
import Vuex from 'vuex'
import App from './App.vue'
Vue.config.productionTip = false
Vue.prototype.$bus = new Vue()
//通过全局方法 Vue.use() 使用插件
Vue.use(Vuex)
//构建数据仓库
const store = new Vuex.Store({
//属性状态容器
state:{
countA:0,
countB:0,
},
//提交触发器
mutations:{
//触发器行为
incrementA(state){
state.countA+=10
},
incrementB(state){
state.countB+=1
},
}
})
let app = ew Vue({
render: h => h(App),
store
}).$mount('#app')
console.log(app.$store)//undefined
解决方法:
使用vue2对应的vuex插件应该使用vuex@3
使用vue3对应的vuex插件应该使用vuex@4
如果你在vue2项目中,所有的配置好了,组件中就是没有$store属性,那么很有可能是安装的vuex插件版本过高