当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 微信小程序自定义菜单切换栏tabbar组件代码实例

微信小程序自定义菜单切换栏tabbar组件代码实例

2020年03月09日  | 移动技术网IT编程  | 我要评论

这篇文章主要介绍了微信小程序自定义菜单切换栏tabbar组件代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

效果图:

wxml代码:

<view class="top_tabbar" > 
 <block wx:for="{{itemname}}" wx:key="{{index}}">
   <view class="item_name {{tabindex == index ? 'active' : ''}}" bindtap="handleitem" data-index="{{index}}">
    <text>{{item}}</text>
   </view>
 </block>
</view>

wxss代码:

.top_tabbar{
 width: 100%;
 background-color: #ffffff;
 display: flex;
 position: fixed;
}
.item_name{
 text-align: center;
 margin:20rpx 60rpx;
 color: grey;
}
.active{
 color: lightgreen;
}
.active text{
  padding-bottom: 10rpx;
  border-bottom: 4rpx solid lightgreen;
}

js代码:

data:{
  itemname: ["军事", "明星", "动漫","风景"],
  tabindex: 0
 },
//获取点击事件
handleitem(e){
  // console.log(e)
  const index = e.currenttarget.dataset.index
  this.setdata({
   tabindex: index
  })
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网