【Vue-Element-Admin】dialog关闭回调事件

背景

点击导入按钮,调出导入弹窗,解析excel数据后,不点击【确认并导入】按钮,直接关闭弹窗,数据违背清理

实现

使用dialog的close回调函数,在el-dialog添加@close,在methods中定义closeDialog,将想清空的变量设置为undefined

<el-button type="text" @click="dialogVisible = true">导入</el-button>

<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  @close="closeDialog">
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确认并导入</el-button>
  </span>
</el-dialog>

<script>
  export default {
    data() {
      return {
        dialogVisible: false
      };
    },
    methods: {
      closeDialog(){
        this.xxx=undefined;
      }
    }
  };
</script>

你可能感兴趣的:(Vue,vue.js,javascript,ecmascript)