Hello i'm converting somme of my web code to an ionic-vue app and i wanted to know if we can catch a this.$emit from my modal using the ionic modal controller insted of classic vuecomponent.
basically i want to translate
<NewAppointmentModal @onSuccess="handleAppointmentCreation"/>
to
this.$ionic.modalController.create({ component: NewAppointmentModal}).then(m => m.present())
//how can i catch the onSuccess event like before
ParentComponent.vue
public openModal() {
return this.$ionic.modalController
.create({
component: ModalComponent,
componentProps: {
data: {
content: 'New Content',
},
propsData: {
//user_id: user_id
},
parent: this,
},
})
.then(m => m.present({
}))
}
public mounted() {
this.$on('close', (foo) => {
this.$ionic.modalController.dismiss()
})
}
ModalComponent.vue
<template>
<ion-button @click="dismissModal()">Close</ion-button>
</template>
<script>
dismissModal() {
this.$parent.$emit('close', { foo: 'bar' })
}
</script>
Brian answered correct, but there are a code line change in Vue 3: ParentComponent.vue
this.$on('close', () => {
this.$ionic.modalController.dismiss()
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With