帮我把这个组件优化成选项卡下面插槽中内容左右滑动时上面标签也会随之滑动 - CSDN文库",
"datePublished": "2024-02-15",
"keywords": " <template> <view class="tabs"> <view class="tabs-header both"> <view v-for="(tab, index) in tabs" :key="index" :class="{ 'active': activeTab === index }" @click="changeTab(index)"> {{ tab }} </view> </view> <view class="tabs-content"> <slot :name="tabs[activeTab]"></slot> </view> </view> </template> <script setup> import { ref } from 'vue' const props = defineProps({ tabs: { type: Array, required: true }, }) let activeTab = ref(0) const changeTab = (index) => { activeTab.value = index } </script> <style lang="scss" scoped> .tabs { display: flex; flex-direction: column; height: 100%; .tabs-header { display: flex; justify-content: space-between; align-items: center; height: 50px; font-size: 30rpx; } .tabs-content { flex: 1; overflow-y: auto; } } .active { position: relative; color: #8a74ee; } .active::after { content: ""; position: absolute; width: 40rpx; height: 8rpx; background-color: #8a74ee; left: 0rpx; right: 0rpx; bottom: -50%; margin: auto; border-radius: 16rpx; } </style>帮我把这个组件优化成选项卡下面插槽中内容左右滑动时上面标签也会随之滑动
相关推荐