【发布时间】:2020-02-08 18:15:35
【问题描述】:
我想稍微简化一下我在 VueX 和组件中的代码。我怎样才能做到这一点? 我想经常使用此代码,这就是为什么我需要将其最小化到最大
组件
this.$store.commit(
"notifications/changeText",
"Pomyślnie zmieniono avatar !"
);
this.$store.commit("notifications/changeStyle", "success");
this.$store.commit("notifications/changeStatus", true);
setTimeout(() => {
this.$store.commit("notifications/changeStatus", false);
}, 5000);
存储/notifications.js
export const state = () => ({
activeStyle: "",
active: false,
text: ""
});
export const mutations = {
changeText(state, text) {
state.text = text;
},
changeStyle(state, style) {
state.activeStyle = style;
},
changeStatus(state, status) {
state.active = status;
}
};
export const getters = {
text(state) {
return state.text;
},
style(state) {
return state.activeStyle;
},
status(state) {
return state.active;
}
};
【问题讨论】: