55 lines
1.1 KiB
Vue
55 lines
1.1 KiB
Vue
<template>
|
|
<view class="u-flex tabs">
|
|
<view class="u-flex-1 u-text-center item"
|
|
:class="{active:index===current}"
|
|
@tap="changeCurrent(index)" v-for="(item,index) in props.list" :key="index">
|
|
{{item}}
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, ref, watch } from 'vue';
|
|
const props=defineProps({
|
|
padding:{type:String},
|
|
list:{type:Array},
|
|
defaultIndex:{
|
|
type:Number,
|
|
default:0
|
|
},
|
|
modelValue:{
|
|
type:Number,
|
|
default:0
|
|
}
|
|
})
|
|
const emit=defineEmits(['change','update:modelValue'])
|
|
let current=ref(props.modelValue||props.defaultIndex||0)
|
|
function changeCurrent(index){
|
|
current.value=index
|
|
emit('update:modelValue',index)
|
|
}
|
|
watch(()=>current.value,()=>{
|
|
emit('change',current.value)
|
|
})
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.tabs{
|
|
padding: 4rpx 10rpx;
|
|
background: #E6F0FF;
|
|
border-radius: 16rpx 16rpx 16rpx 16rpx;
|
|
font-family: Source Han Sans CN, Source Han Sans CN;
|
|
font-size: 28rpx;
|
|
color: #318AFE;
|
|
.item{
|
|
padding: 8rpx 0;
|
|
transition: all .3s ease-in-out;
|
|
}
|
|
.item.active{
|
|
border-radius: 8rpx 8rpx 8rpx 8rpx;
|
|
background-color: $my-main-color;
|
|
color: #fff;
|
|
}
|
|
}
|
|
</style> |