【问题标题】:Element-ui $emit in confirm dialog invalidElement-ui $emit 在确认对话框中无效
【发布时间】:2020-03-13 08:57:12
【问题描述】:

我试图从父页面获取子页面发送的请求,但是不成功。有人可以帮助我,谢谢。

1.父代号

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

2.子代码

<template>
  <span class="do-more">
    <el-dropdown size="mini" @visible-change="dropdownChange($event)" 
      @command="dropdownCommon($event)" >
      <span class="el-dropdown-link">
        <el-button size="mini" type="text" icon="el-icon-more" 
          class="triggleBtn"></el-button>
      </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="delete">del</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </span>
</template>

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

【问题讨论】:

    标签: vuejs2 element-ui


    【解决方案1】:

    将您的代码更改为:

    <template>
      <span class="do-more">
        <el-dropdown size="mini" @visible-change="dropdownChange" 
          @command="dropdownCommon" >
          <span class="el-dropdown-link">
            <el-button size="mini" type="text" icon="el-icon-more" 
              class="triggleBtn"></el-button>
          </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="delete">del</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </span>
    </template>
    
    methods: {
      dropdownCommon(command) {
        if(command === 'delete'){
          this.$confirm("Are you sure to delete?", "confirm")
          .then((config) => {
            this.$emit('onreloadtab')
          })
          .catch(() => {});
        }
        // other command
      }
    }
    

    单击下拉项el-dropdown-item 时,el dropdown@command 事件从el-dropdown-item 接收command 属性值。

    您还可以使用@click 事件代替el-dropdown-item 上的command 属性。

    【讨论】:

    • 点击可以调用delete函数,但是父页面不能得到emit事件。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多