子组件=>
<template>
<div class="dialog">
<div>
<p>{{title}}</p>
<slot name="info"></slot>
<slot name="img"></slot>
<h5>
<button @click="cancel">取消</button>
<button @click="confirm">确定</button>
</h5>
</div>
</div>
</template>
<script>
export default {
name: "Dialog",
data() {
return {
isShow: false
};
},
props: {
title: {
type: String,
default: "标题"
}
},
methods: {
cancel() {
this.$emit("cancel");
},
confirm() {
this.$emit("confirm");
}
}
};
</script>
<style lang="scss">
.dialog {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
z-index: 999;
div {
width: 70%;
height: 35%;
background-color: #fff;
border-radius: 5px;
position: absolute;
padding: 20px 0;
box-sizing: border-box;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: 45% auto;
h5 {
display: flex;
justify-content: space-around;
}
p {
margin: 30px 0;
text-align: center;
}
button {
width: 80px;
height: 35px;
border-radius: 5px;
outline: none;
background-color: transparent;
border: 1px solid #ccc;
}
}
}
</style>
父组件 =>
<template>
<div class="home">
<!-- 弹框 -->
<Dialog v-if="isShow" :title="title" @cancel="qx" @confirm="sure">
<img slot="img" src="/img/none.png" alt />
<p slot="info">产品基本信息</p>
</Dialog>
<button @click="show()">显示弹框</button>
</div>
</template>
<script>
import Dialog from "@/components/dialog/dialog.vue";
export default {
name: "Home",
components: {
GoTop,
Dialog
},
data() {
return {
isShow: false,
title: "您确定要删除吗?"
};
},
methods: {
show() {
this.isShow = !this.isShow;
},
qx() {
this.isShow = false;
},
sure() {
this.isShow = false;
}
}
};
</script>
属性:title
可以传入的值:使用slot:img,商品信息
方法:cancel:取消按钮
confrim: 确定按钮,可以用了传值