vue使用其他组件弹窗(新增编辑)

1. 定义组件

import form from "../form/index.vue" //组件路径
export default {
    components: {
        WebSecurityLogForm: form, //引用组件
    },

2. 使用组件

    <!--  表单  -->
    <WebSecurityLogForm
        :open.sync="open" :id.sync="id" :disabled="disabled" @finishCommit="finishCommit"
    ></WebSecurityLogForm>

初始化的信息return

            disabled: false,
            // 是否显示弹出层
            open: false,
            id: null,

3. 调用组件

 /** 新增按钮操作 */
        handleAdd() {
            this.id = null
            this.disabled = false
            this.open = true
            this.title = '添加安全日志'
        },

4. 子级组件接收

props: {
        id: {
            type: String,
            default: null,
        },
        open: Boolean,
        disabled: Boolean,
    },
    data() {
        return {
            // 弹出层标题
            title: '',
            view: false,
            form: {},
            // 表单校验
            rules: {}
        }
    },
    watch: {
        open(val) {
            if (val) {
                this.get(this.id)
                this.title = '新增安全日志'
            }else {
                this.title = '新增安全日志'
            }
        },
    },

5. 子集组件表单

  <el-dialog class="spec-dialog" :title="title" :visible="open"
             width="80%" append-to-body :close-on-click-modal="false"
             :before-close="cancel">
    132132132
    123132
  </el-dialog>

6. 子集组件点击取消或者确定

// 取消按钮
        cancel() {
            this.form = {}
            this.$emit('finishCommit', true)
        },

7. 父集组件接收回调函数关闭窗口就结束了

finishCommit(row){
            this.open  = false
            this.getList();
        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值