首先定义拥有slot的组件,在slot上命名 name ,在slot上定义动态属性(实际作用在调用组件使用slot的时候用于绑定触发的方法)
<template>
<view>
<view class="grace-flex tool-btn-group">
<view class="grace-flex1 grace-flex container-bg-942B18" v-if="leftStatus">
<slot name="btnLeft" :changeLeft="changeLeft"></slot></view>
<view class="grace-flex1 grace-flex container-bg-124A5C" v-if="rightStatus">
<slot name="btnRight" :changeRight="changeRight"></slot></view>
</view>
</view>
</template>
<script>
export default {
name: "parent",
data() {
return {
};
},
props: {
leftStatus: {
type: Boolean,
default: true
},
rightStatus: {
type: Boolean,
default: true
}
}
}
</script>
<style scoped lang="scss">
.tool-btn-group {
height: 98rpx;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
.grace-flex1 {
color: #FFFFFF;
justify-content: center;
align-items: center;
}
}
</style>
在使用slot的时候需遵循格式: v-slot:名称= { 定义的属性名 }
<article-btn-group >
<template v-slot:btnLeft="{ changeLeft }" ><text @click="changeLeft">联系客服</text>
</template>
<template v-slot:btnRight="{ changeRight }"><text @click="changeRight">立即打卡</text>
</template>
</article-btn-group>