微信小程序tabBar的配置项

187 阅读1分钟

只能在app.json中全局配置

tabBar的配置项

  1. color:tab 上的文字默认颜色。
  2. selectedColor:tab 上的文字选中时的颜色。
  3. backgroundColor:tab 的背景色。
  4. borderStyle:tabbar 上边框的颜色, 仅支持 black / white。
  5. position:tabBar 的位置,仅支持 bottom / top。
  6. list:tab 的列表,最少 2 个、最多 5 个 tab。

list的配置项

  1. pagePath:页面或组件路径,必须在 pages 中先定义。
  2. text:tab 上按钮文字。
  3. iconPath:图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。
  4. selectedIconPath:选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。

当 position 为 top 时,不显示 icon。

配置项图例

image.png

常用配置项

"tabBar": {
    "color": "#000000",
    "selectedColor": "#f3514f",
    "list": [{
        "pagePath": "pages/index/index",
        "text": "主页",
        "iconPath": "/assets/主页.png",
        "selectedIconPath": "/assets/主页 (1).png"
      },
      {
        "pagePath": "pages/category/category",
        "text": "分类",
        "iconPath": "/assets/分类.png",
        "selectedIconPath": "/assets/分类 (1).png"
      },
      {
        "pagePath": "pages/cart/cart",
        "text": "购物车",
        "iconPath": "/assets/购物车.png",
        "selectedIconPath": "/assets/购物车 (1).png"
      },
      {
        "pagePath": "pages/market/market",
        "text": "促销",
        "iconPath": "/assets/促销.png",
        "selectedIconPath": "/assets/促销 (1).png"
      },
      {
        "pagePath": "pages/profile/profile",
        "text": "我的",
        "iconPath": "/assets/我的.png",
        "selectedIconPath": "/assets/我的 (1).png"
      }
    ]
  },

image.png