1

How can I catch the this.$emit from the ionic model controller?
I've found this question, but the solution is deprecated: How can i catch a modal this.$emit using ionic modal controller How should I do this in Vue3?

My code looks like this:

mounted() {
    this.$on('updateMaterialList', () => {
        this.$ionic.modalController.dismiss()
    })
  }

The error is the following:

The Events api `$on`, `$off` `$once` is deprecated.
Yash Maheshwari
  • 1,842
  • 2
  • 7
  • 16

1 Answers1

0

I resolved this recently by passing a prop "update" with the function "updateProducts" and defining the prop "update" in the modal component and then calling it with a this.update(product). This would update the modal without closing it.

this.modal = await modalController.create({
                component: ProductUpdateModal,
                componentProps: {
                  title: 'Update Product',
                  update: (product) => this.updateProducts(product)
              },
                
            })

In modal component:

props: {
  title: {
    type: String,
    default: 'Product'
  },
  update: { type: Function }
},


methods: {
   updateProductInfo(product) {
      this.update(product);         
   },
}
bjacob596
  • 73
  • 8