效果
代码
index.wxml
<!-- 自己滚动区域的组件 -->
<scroll-view class="nav" scroll-x>
<view bindtap="activeNav" data-index="index" class = "nav_item {{index===currentIndexNav?active:''}}" wx:for="{{navList}}" >
{{item.text}}
</view>
</scroll-view>
index.js
在这里插入代码片
data: {
currentIndexNav:0,
navList:[],
},
activeNav(e){
this.setData({
currentIndexNav:e.target.dataset.index,
})
},
getNavList(){
let that = this;
wx.request({
url: 'http://easy-mock.com/mock/5c1dfd98e8bfa547414a5278/bili/navList',
success(res){
if(res.data.code === 0){
that.setData({
navList : res.data.data.navList,
})
}
}
})
},
onLoad: function (options) {
this.getNavList();
},