微信小程序使用weui自定义底部导航栏,切换不同页面显示不同tabbar

在一个微信小程序中想要用到两种不同的tabbar样式,可以使用微信小程序自带插件tabbar

首先在页面json文件中引入 tabbar

{
  "navigationBarTitleText": "个人中心",
  "usingComponents": {
    "mp-tabbar": "/miniprogram_npm/weui-miniprogram/tabbar/tabbar"
  }
}

在wxml文件中使用mp-tabbar,list代表的是显示的列表(文字、图标),current是当前显示的tab,ext-class可以自定义样式

<mp-tabbar ext-class="foot-tabbar" style="position:fixed;bottom:0;width:100%;left:0;right:0;" list="{{list}}" bindchange="tabChange" current="1"></mp-tabbar>

tabbar的列表和事件可以封装到app.js中,在页面中直接引入就好,不用每次使用都要定义

app.js

// app.js
App({
  globalData: {
    indexTabBarLists: [{
      "pagePath": "/pages/index/index",
      "text": "首页",
      "iconPath": "/image/common/home_normal_icon.png",
      "selectedIconPath": "/image/common/home_hover_icon.png"
      // dot: true
    },
    {
      "pagePath": "/pages/mine/mine",
      "text": "我的",
      "iconPath": "/image/common/home_mine_normal_icon.png",
      "selectedIconPath": "/image/common/home_mine_hover_icon.png"
      // badge: 'New'
    }
    ], // tabbar数据
    indexTabBarLists0: [{
      "pagePath": "/pages/index/index",
      "text": "首页",
      "iconPath": "/image/common/home_normal_icon.png",
      "selectedIconPath": "/image/common/home_hover_icon.png"
      // dot: true
    },
    {
      "pagePath": "/PersonalCenter/pages/PersonalCenter/PersonalCenter",
      "text": "我的",
      "iconPath": "/image/common/home_mine_normal_icon.png",
      "selectedIconPath": "/image/common/home_mine_hover_icon.png"
      // badge: 'New'
    }
    ] // tabbar数据
  },
  tabChange: function(e) {
    wx.redirectTo({
      url: e.detail.item.pagePath
    })
  }
})

在页面js中引入封装的list和事件

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: getApp().globalData.indexTabBarLists0, // tabbar数据
  },

  tabChange(e) {
    getApp().tabChange(e);
  },
})

不同页面都能显示不同的tabbar

  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值