I'm using vuejs with bootstrap-vue. I have two components. A list of objects, and my modal. I open my modal when I click on a particular button. Typically, my modal asks : "Are you sure you want to delete these records ?" for instance.
Everything works fine but I don't know how to retrieve the result of the modal in my parent component (if I clicked on 'ok', or 'cancel',...).
How should I do it ?
Since my modal is opened this way :
In my parent component (the list) :
deleteSelectedGroups () {
const modalOptions = {
action: 'delete',
records: this.selectedGroups,
recordFields: ['name', 'usersCount'],
okTitle: 'Delete',
okVariant: 'danger'
}
this.showModalConfirmation(modalOptions)
// ...
// if result of modal is true then ...
},
showModalConfirmation (modalOptions) {
this.$refs.ModalConfirmation.show(modalOptions)
}
In my modal component :
show (modalOptions) {
for (let option in modalOptions) {
this[option] = modalOptions[option]
}
this.$bvModal.show('modalConfirmation')
}
Should I do it simply by returning the value with my methods ?
Or should I do the vuejs way and emit a variable to the parent ?
EDIT : How I'd like my flow to be (pseudo-code) :
deleteselectedGroups () {
openModal()
modalAnswer = modal.getAnswer()
if (modalAnswer === 'OK') {
deleteMyRecords()
}
}