小程序 tabBar菜单

tabBar 介绍

1. tabBar 就是小程序底部的导航菜单,
2. 小程序的 tabBar 使用比较简单,
3. 只需要在全局配置文件`app.json`中加上下面的配置即可

tabBar 案例

  • 参考代码:
{
    "tabBar": {
        "color": "color",
        "selectedColor": "selectedColor",
        "list": [
          {
            "pagePath": "pagePath",
            "iconPath": "iconPath",
            "selectedIconPath": "selectedIconPath",
            "text": "text"
          },
          {
            "pagePath": "pagePath",
            "iconPath": "iconPath",
            "selectedIconPath": "selectedIconPath",
            "text": "text"
          },
        ]
    }
}
  • 目录结构:

在这里插入图片描述

  • 所用图片:

在这里插入图片描述

  • 实际代码(app.json文件):
{
  "pages": [
    "pages/index/index",
    "pages/gengduo/gengduo"
  ],
  "window": {
    "backgroundColor": "#F6F6F6",
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#F6F6F6",
    "navigationBarTitleText": "流星的小程序",
    "navigationBarTextStyle": "black"
  },
  "sitemapLocation": "sitemap.json",
  "style": "v2",
  "tabBar": {
    "color": "#000",
    "selectedColor": "#eee",
    "backgroundColor": "#fff",
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "./images/cookbook.png",
        "selectedIconPath": "./images/cookbook-active.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/gengduo/gengduo",
        "iconPath": "./images/menu.png",
        "selectedIconPath": "./images/menu-active.png",
        "text": "更多"
      }
    ]
  }
}
  • 运行结果:

在这里插入图片描述

  • 注意点:
1. pages数组中的默认页面(第一个元素)一定要出现在tabbar配置的list数组中,如果没有则底部菜单是不显示的;
2. 如果默认页面在菜单的list数组中,但是不是list数组的一个元素,那么默认页面在第一个元素,那个菜单就会被默认选中;
3. 正常来讲,pages数组中的第一个元素(页面),即菜单list数组中的第一个栏目;
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一颗不甘坠落的流星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值