一、先配置vuex
1.运行 cnpm i vuex -S
2.导入包
import Vuex from 'vuex'
3.注册vuex到vue中
Vue.use(Vuex)
4.new Vuex.Store()实例,得到一个数据仓储对象
Var store = new Vuex.Store({
state:{}, //相当于组件中的data,专门用来存储数据
mutations:{}//相当于组件中的methods,操作state中的数据
})
5.将vuex创建的store挂载到App实例上
const App = new Vue({
el:'#app',
render:c => c(App),
store//挂载store