前段书写
<view class="about"><!-- 循环展示出tap信息 --><block wx:for="{{swiperTitle}}"><view bindtap="tapTitle" data-id="{{index}}" class="{{item.class}}">{{item.name}}</view></block></view><!-- 设置滑动模块 --><swiper bindchange="swiperInfo" current="{{current}}"><swiper-item>111111111111111</swiper-item><swiper-item>22222222222222222</swiper-item><swiper-item>333333333333333333333333</swiper-item></swiper></view>
js中书写
// 点击文字tapTitle(e){let index=e.currentTarget.dataset.idlet arr=this.data.swiperTitle//循环处理数组for(let i=0;i<arr.length;i++){//判断并更改if(i==index){arr[i]['class'] = "txtColor";continue;}arr[i]['class'] = "";}//更新页面数据this.setData({swiperTitle:arr,current:index});},// 滑动改变文字颜色样式swiperInfo(e){let index=e.detail.currentlet arr=this.data.swiperTitle//循环处理数组for(let i=0;i<arr.length;i++){//判断并更改if(i==index){arr[i]['class'] = "txtColor";continue;}arr[i]['class'] = "";}//更新页面数据this.setData({swiperTitle:arr,current:index});},