子组件弹窗代码
<template>
<el-dialog :visible="show" width="600px" height="320px" @close="handleClose">
<div>我是----{{ tip }}</div>
<div>可以在这里面写表单内容</div>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleConfirm">确定</el-button>
</span>
</el-dialog>
</template>
<script>
export default {
name: 'pop',
props: {
show: {
type: Boolean,
default: false,
},
tip: {
type: String,
default: '',
},
},
methods:{
handleClose(){
this.$emit('close')
},
handleConfirm(){
this.$emit('submit')
},
}
};
</script>
<style lang="scss">
</style>
父组件代码(需要引用子组件的页面)
<template>
<div>
<el-button type="primary" @click="showPop">点击按钮打开弹窗</el-button>
<!-- 3、页面引用组件 -->
<pop :show="popVisible" :tip="tip" @close="closePop" @submit="submitForm"></pop>
</div>
</template>
<script>
import pop from './component/pop.vue'
export default {
components: {
pop,
},
data() {
return {
tip:'弹窗',
popVisible:false,
}
},
methods:{
submitForm(){
this.popVisible = false
},
closePop(){
this.popVisible = false
},
showPop(){
this.popVisible = true
},
}
};
</script>