首页 > 解决方案 > vuejs $emit 在确认对话框中无效

问题描述

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

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.jsvuejs2

解决方案


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


推荐阅读