97 lines
2.5 KiB
Vue
97 lines
2.5 KiB
Vue
<template>
|
|
<view>
|
|
<su-sticky offsetTop="0" zIndex="20" bgColor="#F2F4F7">
|
|
<scroll-view scroll-x show-scrollbar="false" class="scroll-x-wrapper p-x-32">
|
|
<view class="navs flex-center ju-flex-start nowrap" style="width: auto;">
|
|
<view
|
|
class="navItem flex-center flex-column flex1 shrink nowrap"
|
|
:class="{ tabIndex: i == tabIndex, c34: i == tabIndex }"
|
|
v-for="(v, i) in props.list"
|
|
:key="i"
|
|
@click="navChange(i)"
|
|
>
|
|
<view class="navText"> {{ v.name }} </view>
|
|
<image src="/static/index/active.png" mode="scaleToFill" />
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</su-sticky>
|
|
<view class="goodsPages">
|
|
<goods-item
|
|
v-for="(tab, i) in props.list"
|
|
:key="tab.id || i"
|
|
:ref="(el) => mescrollItems[i] && (mescrollItems[i].value = el)"
|
|
:i="i"
|
|
:index="tabIndex"
|
|
:tabs="props.list"
|
|
></goods-item>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from 'vue';
|
|
import goodsItem from '../goodsItem/goodsItem.vue';
|
|
import { onPageScroll, onReachBottom, onShow } from '@dcloudio/uni-app';
|
|
import useMescrollMore from '@/uni_modules/mescroll-uni/hooks/useMescrollMore.js';
|
|
let props = defineProps({
|
|
list: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
});
|
|
// 动态生成与 tabs 同步的 refs 数组,供 useMescrollMore 使用
|
|
const mescrollItems = props.list.map(() => ref(null));
|
|
const { tabIndex, getMescroll, scrollToLastY } = useMescrollMore(
|
|
mescrollItems,
|
|
onPageScroll,
|
|
onReachBottom,
|
|
);
|
|
// let tabIndex = ref(0);
|
|
const navChange = (i) => {
|
|
// scrollToLastY()
|
|
tabIndex.value = i;
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.scroll-x-wrapper {
|
|
width: 100%;
|
|
white-space: nowrap;
|
|
}
|
|
.navs {
|
|
// padding: 0 32rpx;
|
|
box-sizing: border-box;
|
|
height: 120rpx;
|
|
// padding-bottom: 10rpx;
|
|
.navItem {
|
|
color: #777777;
|
|
font-size: 32rpx;
|
|
// width: 20%;
|
|
// text-align: center;
|
|
// margin-right: 40rpx;
|
|
white-space: nowrap;
|
|
flex-shrink: 0; // 防止被压缩
|
|
image {
|
|
width: 40rpx;
|
|
height: 12rpx;
|
|
opacity: 0;
|
|
margin-top: 12rpx;
|
|
}
|
|
}
|
|
.tabIndex {
|
|
color: #777777;
|
|
font-size: 36rpx;
|
|
font-weight: 500;
|
|
image {
|
|
opacity: 1;
|
|
}
|
|
}
|
|
}
|
|
.goodsPages {
|
|
padding: 0 32rpx;
|
|
padding-top: 12rpx;
|
|
box-sizing: border-box;
|
|
}
|
|
</style>
|