Files
2025-12-22 17:13:05 +08:00

133 lines
2.3 KiB
Vue

<template>
<view>
<scroll-view scroll-x class='tab-list' :scroll-into-view="'tab'+(activeIndex-1)" :scroll-with-animation="true"
:style="{background: bgColor}">
<view class='tab-item text-bold rel' v-for="(item,index) in list" :key="index"
@tap='handerTabChange(index)' :id="'tab'+index"
:style="{width:width,height:height,lineHeight:height,color:index==activeIndex? activeColor : color,fontSize:fontSize}">
{{item.title || item}}
<view class="abs line" :style="{background: activeColor}" v-if="index==activeIndex && haveLine"></view>
<view v-if="item.number" class="item-msg c-base f-icontext abs"
:style="{width: item.number<10 ? '30rpx' : '50rpx',right: msgRight }">
{{item.number < 100 ? item.number : '99+'}}
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
name: 'tab',
props: {
list: {
type: Array,
default () {
return []
}
},
activeIndex: {
type: Number || String,
default () {
return 0
}
},
color: {
type: String,
default () {
return '#333'
}
},
activeColor: {
type: String,
default () {
return '#e73535'
}
},
bgColor: {
type: String,
default () {
return '#fff'
}
},
width: {
type: String,
default () {
return ''
}
},
height: {
type: String,
default () {
return ''
}
},
haveLine: {
type: Boolean,
default () {
return true
}
},
msgRight: {
type: String,
default () {
return '5rpx'
}
},
fontSize: {
type: String,
default () {
return '28rpx'
}
}
},
created() {
},
data() {
return {
}
},
methods: {
handerTabChange(index) {
this.$emit('change', index);
}
},
}
</script>
<style lang="scss">
.tab-list {
white-space: nowrap;
width: 100%;
}
.tab-item {
display: inline-block;
text-align: center;
line-height: 100rpx;
padding: 0 20rpx;
border-color: #fff;
box-sizing: border-box;
.line {
width: 80rpx;
height: 6rpx;
border-radius: 6rpx;
left: 50%;
bottom: 0rpx;
margin-left: -40rpx;
}
}
.item-msg {
width: 30rpx;
height: 30rpx;
line-height: 30rpx;
border-radius: 15rpx 15rpx 15rpx 0;
background: #f12c20;
top: 5rpx;
}
</style>