Vuex的
store接受
plugins选项,这个选项暴露出每次
mutation的钩子。
Vuex插件就是一个函数,它接收
store作为唯一参数:
const myPlugin = store => { // 当 store 初始化后调用 store.subscribe((mutation, state) => { // 每次 mutation 之后调用 // mutation 的格式为 { type, payload } });};然后像这样使用:
const store = new Vuex.Store({ // ... plugins: [myPlugin]});官方文档



