mapState
function mapState(stateList) {
let obj = {};
for (let i = 0; i < stateList.length; i++) {
let stateName = stateList[i];
obj[stateName] = function () {
return this.$store.state[stateName];
};
}
return obj;
}
mapGetters
function mapGetters(gettersList) {
let obj = {};
for (let i = 0; i < gettersList.length; i++) {
let getterName = gettersList[i];
obj[getterName] = function () {
return this.$store.getters[getterName];
};
}
return obj;
}
mapMutations
function mapMutations(mutationList) {
let obj = {};
for (let i = 0; i < mutationList.length; i++) {
obj[mutationList[i]] = function (payload) {
this.$store.commit(mutationList[i], payload);
};
}
return obj;
}
mapActions
function mapActions(actionList) {
let obj = {};
for (let i = 0; i < actionList.length; i++) {
obj[actionList[i]] = function (payload) {
this.$store.dispatch(actionList[i], payload);
};
}
return obj;
}
打赏作者
您的打赏是我前进的动力
微信
支付宝
vuex 中的严格模式
上一篇
评论