微信小程序tabBar 设置和使用整理

一、从配置文件中设置tabBar

app.json配置文件中配置tab的项:

  "tabBar": {
    "color": "#000",
    "selectedColor": "#F69C21",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页",
        "iconPath": "style/image/index.png",
        "selectedIconPath": "style/image/index1.png"
      },
      {
        "pagePath": "pages/tabone/tabone",
        "text": "订单",
        "iconPath": "style/image/order.png",
        "selectedIconPath": "style/image/order1.png"
      }
    ]
  },

更多属性说明:

https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#tabBar

 

二、使用js代码修改tabBar

关于tabBar的目前支持的jsAPI如下:

Tab Bar

名称功能说明
wx.showTabBarRedDot显示 tabBar 某一项的右上角的红点
wx.showTabBar显示 tabBar
wx.setTabBarStyle动态设置 tabBar 的整体样式
wx.setTabBarItem动态设置 tabBar 某一项的内容,2.7.0 起图片支持临时文件和网络文件
wx.setTabBarBadge为 tabBar 某一项的右上角添加文本
wx.removeTabBarBadge移除 tabBar 某一项右上角的文本
wx.hideTabBarRedDot隐藏 tabBar 某一项的右上角的红点
wx.hideTabBar隐藏 tabBar

常用操作

1.目前已经支持唏嘘该tab的项内容链接地址,目前不支持删除某一项

2.目前支持整体显示和隐藏 tabBar

3.目前支持显示或隐藏红点  、显示或隐藏badge

 

在app onLanch的时候即可修改tab项

App({
  onLaunch: function () {
    //修改tab项
    wx.setTabBarItem({
      index: 0,
      text: 'text',
      pagePath: '/pages/textarea/textarea',
      iconPath: '/style/image/address.png',
      selectedIconPath: '/style/image/address.png',
      success: res => {
        console.info(res);
      },
      fail: res => {
        console.info(res);
      }
    });

    //隐藏tab项
    // wx.hideTabBar({
    // })
    //显示红点
    wx.showTabBarRedDot({
      index: 1,
    })
    //显示红字,badge
    wx.setTabBarBadge({
      index: 0,
      text: '3',
    });
  },
  globalData: {
    userInfo: null
  }
})

 

更多:

解决微信支付中申请退款的基础连接已经关闭的错误

维信小程序button样式重写

微信小程序选择位置接口wx.chooseLocation

 

转载于:https://my.oschina.net/tianma3798/blog/3070397

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值