Vue——element dialog关闭弹窗,检验未去掉

问题:
element dialog关闭弹窗,检验未去掉

父组件:
<el-button @click="add">新增</el-button>
<el-button @click="edit">编辑</el-button>

<!-- 新增 or 编辑 -->
 <Add :visible.sync="visible" :infoData="infoData" @getLists="getLists"></Add>
import Add from './add.vue';
import config from './config.js';
components: { Add },

add() {
      this.infoData = {};
      this.type = 'add';
      this.visible = true;
    },
edit(row) {
      if (row.id) {
        energyDetail(row.id).then(res => {
          if (res.data) {
            this.parData = res.data;
            this.visible = true;
          }
        });
      }
  }
子组件:
<el-dialog :title="parData.id ? '编辑' : '新增'" v-if="showVisible" :visible.sync="showVisible" @close="close" @confirm="confirm" @open="open" >
   <el-form label-position="top" ref="baseFormRef" :model="formModel" :rules="bsaeFormRules"></el-form>

</el-dialog>

import config from './config.js';
export default {
  mixins: [config],
  props: {
    visible: { type: Boolean, default: false },
    parData: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },

  computed: {
    showVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit('update:visible', val);
      }
    }
  },
  watch: {
    showVisible(val) {//监听弹窗,打开时调用open回调方法调接口,
      if (val) this.open();
    }
  },
},
 methods: {
    open() {//open()事件弹窗打开时的回调。
      if (this.infoData.id) {//编辑
        this.formModel = { ...this.infoData, time: [] };
        this.formModel.time.push(this.infoData.beginTime);
        this.formModel.time.push(this.infoData.endTime);
      } else {//新增
        this.formModel = { time: [] };
      }
    },
    confirm(){
       //保存成功时的操作......
    },
    close(){
     this.$refs.baseFormRef.resetFields();//清空表格数据
    }
  },

总结:
1.vue父传子
2.vue watcher监听
3.element dialog open事件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值