vuex
插件的简单使用
vuex 插件就是一个函数,接收一个 store 作为唯一参数。
js
const vuexPer = function(store) {
console.log(store);
store.subscribe((mutation, state) => {
// 每次改变 state 都会执行这个回调函数
// 这里的 state 是最新的状态。
})
}
export default new Vuex.Store({
state: {
count: 1
},
getters: {
},
mutations: {
add(state, payload) {
state.count ++
}
},
actions: {
},
modules: {
},
plugins: [vuexPer]
})