Answer the question
In order to leave comments, you need to log in
How to properly implement calling multiple dialog boxes in Vue (Vuex, Element UI)?
Now the call of one window is implemented, by changing its visibility state in the Store
. There is a modals object in the store. And dialogSignUp and dialogSignIn are two windows
state: {
modals: {
dialogSignUp: false,
dialogSignIn: false
}
},
mutations: {
DIALOG_SHOW(state, value) {
state.modals.dialogSignUp = value;
}
},
actions: {
dialogShow({ commit }, value) {
commit("DIALOG_SHOW", value);
}
},
getters: {
dialogSignUp: state => {
return state.modals.dialogSignUp;
}
}
computed: {
modal: {
get() {
return this.$store.getters.dialogSignUp;
},
set(value) {
this.$store.dispatch("dialogShow", value);
}
}
},
<el-button plain type="default" size="small" @click="modal = !modal">Popup</el-button>
<el-dialog :title="title" :visible="modal" @close="modal = false">
<slot></slot>
<span slot="footer" class="dialog-footer">
<el-button @click="modal = false">Отмена</el-button>
<el-button type="primary" @click="popupAction">Ок</el-button>
</span>
</el-dialog>
Answer the question
In order to leave comments, you need to log in
Pass to the mutation instead of just the state of the dialog, an object of the form { имя_диалога: состояние }
. Then, when updating the state of the dialogs, there will be no need to refer to them by name:
mutations: {
dialogShow: (state, payload) => Object.assign(state.modals, payload),
},
modals() {
return new Proxy(this.$store.state.modals, {
set: (target, prop, value) => {
this.$store.commit('dialogShow', { [prop]: value });
return true;
},
});
},
<el-button @click="modals.dialogSignIn = true">sign in</el-button>
<el-dialog :visible="modals.dialogSignIn" @close="modals.dialogSignIn = false">
<span slot="footer" class="dialog-footer">
<el-button @click="modals.dialogSignIn = false">Закрыть</el-button>
</span>
</el-dialog>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question