一普监、先配置vuex
1.運(yùn)行 cnpm i vuex -S
2.導(dǎo)入包
import Vuex from 'vuex'
3.注冊vuex到vue中
Vue.use(Vuex)
4.new Vuex.Store()實例,得到一個數(shù)據(jù)倉儲對象
Var store = new Vuex.Store({
state:{},? //相當(dāng)于組件中的data,專門用來存儲數(shù)據(jù)
mutations:{}//相當(dāng)于組件中的methods,操作state中的數(shù)據(jù)
})
5.將vuex創(chuàng)建的store掛載到App實例上
const App = new Vue({
el:'#app',
render:c => c(App),
store//掛載store