小程序开发-底部导航

底部导航

设置tabbar数据

module.exports = [{
    "pagePath": "pages/index/index",
    "text": "活动专区",
    "iconPath": "https://jw-vip-project.cn-sh2.ufileos.com/marriott/wxapp/home_nor.png",
    "selectedIconPath": "https://jw-vip-project.cn-sh2.ufileos.com/marriott/wxapp/home_pre.gif",
    "auth": 0
  },
  {
    "pagePath": "pages/mine/index/index",
    "text": "更多",
    "iconPath": "https://jw-vip-project.cn-sh2.ufileos.com/marriott/wxapp/mine_nor.png",
    "selectedIconPath": "https://jw-vip-project.cn-sh2.ufileos.com/marriott/wxapp/mine_pre.gif",
    "auth": 0
  }
]

设置数据以及样式

import tabbarList from './tabBarlist/router.js'   //引入数据
  data: {
    tabbarList: tabbarList,
  },

获取父级数据

  properties: {
    activeIdx: {
      type: Number,
      value: 0
    },
  },

ipx适配

let $this= this
   wx.getSystemInfo({
      success: function (res) {
        var model = res.model;
        var iponeX = model.indexOf("iPhone X")
        if (iponeX == '0') {
         	$this.setData({
        	 	iphonexnavbar:ipx
         	})
        } else {
          	$this.setData({
         		iphonexnavbar:''
         	})
        }
      }
    })

wxml

<view class='tabbar {{iphonexnavbar}}'>
  <view class="tabbar-content">
    <view class='tabbar-item {{activeIdx === index ? "active" : ""}}' wx:for='{{tabbarList}}' wx:key='{{item.pagePath}}' bindtap='handleItemTap' data-path='{{item.pagePath}}' data-idx='{{index}}'>
      <view class='tabbar-item-icon'>
        <image src='{{activeIdx === index ? item.selectedIconPath : item.iconPath}}'></image>
      </view>
      <view class='tabbar-item-text'>{{item.text}}</view>
    </view>
  </view>
</view>

pages页面使用

<tabbar activeIdx='0' ></tabbar>

样式

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  font-size: 0;
  background: #000;
  z-index: 999;
  color: #595757;
}

.tabbar-content {
  display: flex;
  font-size: 0;
  position: relative;
  width: 100%;
  height: 100%;
  justify-content: space-between;
  align-items: center;
}

.tabbar-item {
  height: 100%;
  width: 200rpx;
  color: #595757;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.tabbar-item-icon {
  margin-bottom: 6rpx;
  height: 56rpx;
  z-index: 1000
}

.tabbar-item-icon image {
  width: 50rpx;
  height: 50rpx;
}

.tabbar-item-text {
  font-size: 26rpx;
  line-height: 34rpx;
  height: 30rpx;
}

.tabbar-item.active {
  color: #fff;
}
.ipx{
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值