Hi,
I have a component confirm delete modal which I show when I want to delete something. It’s simple component which pops up when I hit delete button. I call it like this from other vue pages:
<confirm-delete-dialog
:show="showConfirmDeleteDialog" // true/false show or hide modal
:item="itemToDelete" // what to delete (I want to reuse it for different things)
@delete-user="deleteUser" // here we delete user (can be something else e.g. post)
@close="handleCloseConfirmDelete" // what to do, when modal is closed (reset some data)
></confirm-delete-dialog>
in component I have like this:
export default {
props: {
show: {
type: Boolean,
required: true,
},
item: {
type: String,
required: true
}
},
emits: ['item', 'close'],
methods: {
deleteItem() {
this.$emit('item');
this.$emit('close');
}
}
};
This doesn’t work as in this case I want to emit “delete-user” which is the value of props item. Vue complains about:
Vue warn]: Extraneous non-emits event listeners (deleteUser were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the “emits” option.
So in my main component deleteUser was not received as modal didn’t emit it.
I am doing this way as I want to use same modal to confirm deletion of different items.
How can I dynamical pass custom event, based from where the component was called, e.g. Delete User, Delete Post, etc.