菜鸟生成记(92)
为毕设,学习一下Vue。
v-slot实现弹窗
(1)MyPopoverEdit.vue
<template>
<div id="div-max" style="height: 50px;width: 80px;float: left;">
<!-- 名(name)为popover1的插槽 -->
<slot name="popover1"></slot>
<!-- 参数控制浮窗是否显示 -->
<template v-if="isShowPopover">
<div id="div-slot">
<!-- 名(name)为popover2的插槽 -->
<slot name="popover2"></slot>
</div>
</template>
</div>
</template>
<script>
export default {
name: "MyPopoverEdit",
props:['isShowPopover'],
};
</script>
<style scoped>
#div-max{
height: 50px;
width: 50px;
margin-left: 2px;
}
#div-slot{
background-color: #FFFFFF;
text-align: center;
line-height: 50px;
height: 50px;
width: 130px;
margin-top: -90px;
border-radius: 10px;
border: 1px solid #EBEEF5;
}
</style>
(2)MyMainPage.vue
<template>
<div id="div-max">
<!-- isShowPopover的值通过prop传给MyPopoverEdit组件 -->
<MyPopoverEdit :isShowPopover="isShowPopover">
<!--
popover1:MyPopoverEdit组件中一个插槽(slot)的名字(name),下同
<template v-slot:popover1></template>包裹的内容用来放入插槽popover1中,下同
-->
<template v-slot:popover1>
<el-button size="mini"
type="primary"
icon="el-icon-edit"
@click="showPopper"
>
</el-button>
</template>
<template v-slot:popover2>
<el-button size="mini" type="primary" @click="closePopover">取消</el-button>
<el-button size="mini" type="danger">保存</el-button>
</template>
</MyPopoverEdit>
</div>
</template>
<script>
import MyPopoverEdit from "@/MyPopoverEdit.vue";
export default {
name: "MyMainPage",
components: {MyPopoverEdit},
data(){
return{
isShowPopover:false,
}
},
methods:{
showPopper(){
this.isShowPopover=!this.isShowPopover
},
closePopover(){
this.isShowPopover=false
}
},
mounted() {
}
}
</script>
<style scoped>
#div-max{
background-color: #1b6d85;
height: 400px;
width: 400px;
margin-top: 100px;
margin-left: 100px;
}
</style>