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

1、从配置文件中设置tabBarjavascript

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

"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"
      }
    ]
  },

更多属性说明:java

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

 

2、使用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

经常使用操做api

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

2.目前支持总体显示和隐藏 tabBar网络

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

 

在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

相关文章
相关标签/搜索