(一)安装vuex包
npm install vuex
(二)创建vuex实例
(三)main.js中将vuex实例挂载到vue对象上
main.js
import Vuex from 'vuex'
Vue.use(Vuex)
const store=new Vuex.Store({ //创建vuex实例
state:{
count:0
}
})
new Vue({
//vuex实例挂载到vue对象上
store,
render:h=>h(App)
}).$mount("#app")