<template>
<el-dialog
class="my-dialog"
width="70%"
:visible.sync="dialogVisible"
>
<div>dialog内容区域</div>
<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>
</template>
<script>
export default {
name: 'MyDialog',
props: {
show: {
type: Boolean,
default: false
}
},
computed: {
dialogVisible: {
get() {
return this.show
},
set(val) {
this.$emit('update:show', val)
}
}
}
}
</script>
<style lang="less" scoped></style>
使用MyDialog组件
<template>
<el-button @click="showMyDialog = !showMyDialog">打开/关闭MyDialog</el-button>
<MyDialog :show.sync="showMyDialog"></MyDialog>
</template>
<script>
data() {
return {
showMyDialog: false
}
}
</script>
<style lang="less" scoped></style>