<template>
<div>
<el-dialog
title="title"
:visible.sync="visible"
@close="$emit('update:show', false)"
:show="show"
:close-on-click-modal="false"
>
<el-form ref="form" :model="formData" label-width="80px" v-if="formData">
<el-form-item label="活动名称">
<el-input v-model="formData.name"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="visible = false">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
visible: this.show,
formData:this.formData
}
},
props: {
show: {
type: Boolean,
formData:Object
}
},
watch: {
show() {
this.visible = this.show
console.log(this.show)
}
}
}
</script>
使用组件
<template>
<div>
<service-dialog :show.sync="show"></service-dialog>
<el-button @click="open">click</el-button>
</div>
</template>
<script>
import serviceDialog from './serviceDialog'
export default {
data () {
return {
show: false
};
},
methods: {
open () {
this.show = true;
}
},
components: {
serviceDialog
}
};
</script>