子组件内容
<template>
<div>
<el-dialog
title="表单"
:visible="dialogVisible"
width="45%"
@close="handleClose"
>
<span>子组件弹出框</span>
<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>
</div>
</template>
?
<script>
export default {
name: 'DialogForm',
props: {
DialogFlag: {
default: false
}
},
data () {
return {
// 开关
dialogVisible: false,
}
},
watch: {
DialogFlag () {
this.dialogVisible = this.DialogFlag
}
},
created () {
console.log('审批页面执行')
},
methods: {
// 表单关闭事件-通知父组件关闭(.syanc)
// 不通知父组件可能会报错,导致只能打开一次
handleClose () {
this.$emit('update:DialogFlag', false)
},
}
}
</script>
父组件内容
// 引入组件
import DialogForm from './components/DialogForm.vue'
?
//注册组件
components: {
DialogForm
},
//data
DialogFlag: false
?
// html
<DialogForm :DialogFlag.sync="DialogFlag" />
?
// 使用组件
<el-button
type="primary"
icon="el-icon-circle-plus-outline"
@click="examinadd"
>打开表单</el-button
>
examinadd () {
this.DialogFlag = true
},
现在已经把组件封装进去了,后面就可以根据你自己需求去加内容了