子组件
<template>
<div class="btn_box">
<div :class="['btn',classType]">
<slot name="btn"></slot>
</div>
</div>
</template>
<script setup>
import { computed, useAttrs } from 'vue';
defineOptions({
inheritAttrs: false
});
let attrs = useAttrs();
const classTypeList = ['primary', 'success', 'info', 'warning', 'danger'];
const classType = computed(() => {
let lowType = attrs.type.toLowerCase()
if(!classTypeList.includes(lowType)) return 'info'
return lowType
})
</script>
<style lang="scss" scoped>
$btnClass: ('primary', 'success', 'info', 'warning', 'danger');
$btnColors: #409eff, #67c23a, #909399, #e6a23c, #f56c6c;
@for $i from 1 through length($btnColors) {
$ClasStyle:nth($btnClass, $i);
.btn_box{
cursor: pointer;
@extend .center;
}
.btn{
border-radius: 10px;
padding: 10px 15px;
}
.btn.#{$ClasStyle}{
$color: nth($btnColors, $i);
background: $color;
color: #fff;
&:hover{
background: lighten($color: $color, $amount:10%);
}
&:active{
background: darken($color: $color, $amount:10%);
}
&:disabled{
background: lighten($color: $color, $amount:20%);
color: lighten($color: $color, $amount:40%);
}
}
}
.center{
display: flex;
justify-content: center;
align-items: center;
}
</style>
父组件
<template>
<Btnview :type="'primary'">
<template v-slot:btn>
<div>998877</div>
</template>
</Btnview>
</template>
<script lang="ts" setup name="login">
const Btnview = defineAsyncComponent(()=>import('../../components/button/button.vue'));
</script>``
<style lang="less" scoped>
</style>