下面代码是结合scroll和swiper组合使用,实现tab和内容的切换,
scroll是横向滚动,
<template>
<view class="content">
<view>
<scroll-view
class="scroll-view_H"
scroll-x="true"
@scroll="scroll"
scroll-left="120"
>
<view
id="demo1"
class="scroll-view-item_H uni-bg-red"
v-for="(item, index) in tab"
:key="index"
@click="scroll(index)"
><view :class="tabIndex == index ? 'active' : ''">
{
{ item }}
</view></view
>
</scroll-view>
<swiper @change="handle_swiperChange" :current="tabIndex" next-margin="100rpx">
<swiper-item