vuex中subscribe的使用
vuex中subscribe的使用会在每个 mutation 完成后调用,接收 mutation 和经过 mutation 后的状态作为参数App.vuethis.$store.commit('add')store.jsconst store = new Vuex.Store({state:{name:'zs',age:18},mutations:{add(state){consol
·
vuex中subscribe的使用
-
会在每个 mutation 完成后调用,接收 mutation 和经过 mutation 后的状态作为参数
App.vue
this.$store.commit('add')store.js
const store = new Vuex.Store({ state:{ name:'zs', age:18 }, mutations:{ add(state){ console.log(state.age); } } }) store.subscribe((mutation,state) => { console.log(mutation.type) console.log(state) }) /* 18 add { name : 'zs', age : 18} */
更多推荐



所有评论(0)