<template>
|
<view class="flex top-tabs">
|
<view
|
class="top-tab t-grey p10"
|
v-for="(item, index) in tabs"
|
:key="index"
|
:class="{ active: index === flg }"
|
@tap="changeIndex(index)"
|
>
|
{{ item.name || item.label || '' }}
|
</view>
|
</view>
|
</template>
|
|
<script setup lang="ts">
|
|
interface TabItem {
|
name?: string
|
label?: string
|
[key: string]: any
|
}
|
|
const props = defineProps<{
|
tabs: TabItem[]
|
flg: number
|
}>()
|
|
const emits = defineEmits<{
|
(e: 'update:flg', val: number): void
|
(e: 'change', val: number): void
|
}>()
|
|
function changeIndex(index: number) {
|
if (index !== props.flg) {
|
emits('update:flg', index)
|
emits('change', index)
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.top-tabs {
|
display: flex;
|
.top-tab {
|
color: #ffffff;
|
flex: 1;
|
text-align: center;
|
}
|
|
.top-tab.active {
|
color: #ffffff;
|
font-weight: 600;
|
font-size: 36rpx;
|
line-height: 32rpx;
|
text-align: center;
|
position: relative;
|
}
|
|
.top-tab.active::before {
|
content: '';
|
position: absolute;
|
left: 16rpx;
|
right: 16rpx;
|
bottom: 8rpx;
|
height: 8rpx;
|
background: #ffffff;
|
border-radius: 4rpx;
|
}
|
}
|
</style>
|
|