首先先对文字写样式xcss
然后写前台index.wxml
<view class="nav_wrapp">
<!--自己滚动-->
<scroll-view class="nav" scroll-x>
<view bindtap="activeNav" data-index="{{index}}" class="nav-item {{index===currentIndexnav?'active':''}}" wx:for="{{navList}}" wx:key="{{index}}">
{{item.navname}}
</view>
</scroll-view>
</view>
然后写index.js
data: {
//导航栏选中菜单索引
currentIndexnav:0,
//导航栏标签
navList: []
},
activeNav(e){
this.setData({
currentIndexnav:e.target.dataset.index
})
},