子组件 popup.vue
<template>
<div class="popup"> <!-- 封装弹框 -->
<el-dialog
:title="dialogTitle"
:visible.sync="dialogVisible"
:width="popupWidth"
:before-close="handleClose">
<slot>
<p>弹框自定义的内容</p>
</slot>
<span slot="footer" class="dialog-footer">
<el-button @click="Cancel">取 消</el-button>
<el-button type="primary" @click="Save">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'popup',
props: {
dialogTitle: {
type: String,
default: '标题'
},
visible: {
type: Boolean,
default: false
},
popupWidth: {
type: String,
default: '550px'
}
},
computed: {
dialogVisible: {
get() {
return this.visible
},
}
},
methods: {
Cancel() {
this.$emit('resetPopupData')
},
Save() {
this.$emit('submitPopupData')
},
handleClose() {
this.$emit('handleClose')
}
}
}
</script>
<style lang="scss">
.popup {
width: 550px;
.el-dialog {
z-index: 9;
background-color: #fff;
border-radius: 5px;
margin-top: 10% !important;
}
.el-dialog__header {
width: 100%;
height: 40px;
line-height: 38px;
border-bottom: 1px solid #f6f7f9;
box-sizing: border-box;
padding: 0 20px;
font-size: 16px;
}
.el-dialog__close.el-icon.el-icon-close {
font-size: 20px;
width: 17px;
height: 17px;
}
.el-button.el-button--default {
width: 88px;
color: #1182fb;
border: 1px solid #1182fb;
}
.el-button.el-button--primary {
width: 88px;
}
.el-dialog__body {
padding: 24px 32px;
box-sizing: border-box;
}
.el-dialog__headerbtn {
top: 4px;
}
.el-dialog__title {
color: #3c4354;
font-size: 16px;
line-height: 16px;
}
.el-dialog__footer {
text-align: center;
}
}
</style>
父组件
template
<popup
:dialogTitle="dialogTitle"
:visible.sync="dialogVisible"
@resetPopupData="resetPopupData"
@submitPopupData="submitPopupData"
@handleClose="handleClose"
:popupWidth="'550px'">
<div>
内容填充
</div>
</popup>
data
data(){
return{
dialogVisible: true, // 弹框的出现与否
dialogTitle: '通过', // 标题
}
}
methods
methods: {
// 点击取消的事件
resetPopupData () {
// 这里可重置数据
this.dialogVisible = false
},
// 点击确定的按钮
async submitPopupData () {
console.log('kkk')
this.dialogVisible = false
},
// 关闭弹框(头部的X)
handleClose () {
this.dialogVisible = false
}
}