如何使用离子模态控制器捕获模态 this.$emit

Ram*_*ify 4 ionic-framework vue.js ionic-vue

您好,我正在将我的一些网络代码转换为 ionic-vue 应用程序,我想知道我们是否可以使用经典 vuecomponent 的 ionic 模态控制器从我的模态中捕获 this.$emit。

基本上我想翻译

<NewAppointmentModal @onSuccess="handleAppointmentCreation"/>
Run Code Online (Sandbox Code Playgroud)

this.$ionic.modalController.create({ component: NewAppointmentModal}).then(m => m.present())
//how can i catch the onSuccess event like before 
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 5

父组件.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()
   })
}
Run Code Online (Sandbox Code Playgroud)

模态组件.vue

<template>
   <ion-button @click="dismissModal()">Close</ion-button>
</template>
<script>
   dismissModal() {
     this.$parent.$emit('close', { foo: 'bar' })
   }
</script>
Run Code Online (Sandbox Code Playgroud)

  • 似乎在 Vue 3 中“this.$on”已被弃用...... (2认同)