微信小程序> 小程序顶部tab切换

小程序顶部tab切换

浏览量:1642 时间: 来源:康康桑思密达

首先我们看效果
小程序

接下来是wxml部分代码

!-- tab框  --view class="nav_title"  view class="nav_tab"  !-- 如果选中的下表等于当前的索引,就使用active class名,否则class名为common --    view wx:for="{{list}}" wx:key="list" class="{{selected==index?'active':'common'}}" data-index='{{index}}' bindtap="selected"{{item}}  !-- 如果选中的下表等于当前的索引,就添加下划线 --         view class="{{selected==index?'nav_underline':''}}"/view    /view  /view  !-- tab框显示内容 --  view wx:if="{{selected == 0}}"aaa/view  !-- 待使用 --  view wx:if="{{selected == 1}}"bbb/view  !-- 待取消 --  view wx:if="{{selected == 2}}"ccc/view/view

wxss部分代码

/* 页面背景色 */page {  background: rgba(247, 247, 247, 1);}.nav_tab {  width: 702rpx;  margin: 20rpx auto;  height: 100rpx;  display: flex;  background: #fff;  border-radius: 10rpx;  flex-direction: row;}/* 未选中的样式 */.common {  line-height: 100rpx;  text-align: center;  flex: 1;  color: #333;  font-size: 28rpx;  opacity: 0.5;}/* 选中时的样式 */.active {  line-height: 100rpx;  text-align: center;  color: #ef9ba8;  flex: 1;  font-size: 28rpx;}/* 下划线的样式 */.nav_underline {  background: #ef9ba8;  width: 54rpx;  height: 6rpx;  margin-top: -10rpx;  margin-left: 70rpx;  border-radius: 8rpx;}

最后是js部分

// pages/mine/reserve/reserve.jsPage({  /**   * 页面的初始数据   */  data: {    selected: 0,    list: ['全部', '待使用', '待取消'],  },  //tab框  selected: function (e) {    let that = this    console.log(e)    let index = e.currentTarget.dataset.index    console.log("index",index)    if (index == 0) {      that.setData({        selected: 0      })    } else if (index == 1) {      that.setData({        selected: 1      })    } else {      that.setData({        selected: 2      })    }   },  /**   * 生命周期函数--监听页面加载   */  onLoad: function (options) {  },  /**   * 生命周期函数--监听页面初次渲染完成   */  onReady: function () {  },  /**   * 生命周期函数--监听页面显示   */  onShow: function () {  },  /**   * 生命周期函数--监听页面隐藏   */  onHide: function () {  },  /**   * 生命周期函数--监听页面卸载   */  onUnload: function () {  },  /**   * 页面相关事件处理函数--监听用户下拉动作   */  onPullDownRefresh: function () {  },  /**   * 页面上拉触底事件的处理函数   */  onReachBottom: function () {  },  /**   * 用户点击右上角分享   */  onShareAppMessage: function () {  }})

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎