【问题标题】:vuejs $emit in confirm dialog invalidvuejs $emit 在确认对话框中无效
【发布时间】:2019-11-15 10:38:23
【问题描述】:

我尝试从父页面获取子页面发送的请求,但是不成功。

1.父代号

<do-more @onreloadtab="reloadTab" :selectFolder="selectFolder"></do-more>
methods: {
      reloadTab:function(){
            console.log('reload')
      }
}

2.子代码

methods: {
      async delete (row) {
        let that = this
        await this.$confirm("Are you sure to delete?", "confirm")
       .then((config) => {
             that.$emit('onreloadtab')
            return
         })
          .catch(() => {
          });
}

为什么父母不能得到发射消息?

【问题讨论】:

    标签: vue.js vuejs2


    【解决方案1】:

    在使用await 之后,您不需要使用then 方法。 then 方法在 Promise 之后调用,但 await 返回 Promise 的 inside 值,而不是 Promise。因此,请尝试在没有 then 方法块的 await 语句之后调用 emit

    【讨论】:

    • 谢谢,问题依旧,但我找到了另一种方法。
    【解决方案2】:

    为了在您的父母中捕获事件,您需要created() 这是您在父母中记录事件的方式

    <template>
      <do-more :selectFolder="selectFolder"></do-more>
    </template>
    
    <script>
    export default {
        data(){
            return{
    
            }
        },
        created() {
            reloadTab(event){
                console.log(event) 
            }
        }    
    }
    </script>

    【讨论】:

      猜你喜欢
      • 2020-03-13
      • 2018-10-10
      • 2021-02-01
      • 2011-05-24
      • 2016-02-02
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多