小程序配置文件 —— 14 全局配置 - tabbar配置

全局配置 - tabBar配置

tabBar 字段:定义小程序顶部、底部 tab 栏,用以实现页面之间的快速切换;可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面;

在上面图中,标注了一些 tabBar 常用的配置项:

  • borderStyle:用来控制 tab 栏上方的一条边线,控制边线是否需要进行演示或者隐藏;
  • backgroundColor:用来配置整条 tab 栏的背景色;
  • selectedColor:用来配置 tabBar 被激活时对应的文字颜色;
  • color:用来配置 tabBar 没有被激活时文字的颜色;
  • list:list 是一个数组,数组中每一项都是一个对象,在对象中可以配置 selectedIconPath、pagePath、iconPath、text;selectedIconPath 表示当对应的 tabBar 被激活时对应 icon 的路径,pagePath 表示当对应的 tabBar 被激活时需要跳转的页面路径,iconPath 用来配置当前 tabBar 没有被激活时对应 icon 的路径,text 用来定义每个 tabBar 对应的文字是什么;

注意事项:tab 按数组的顺序排序。list 配置最少配置 2 个,最多 5 个;可以通过官方文档:tabBar 配置项来学习进行相关配置;

打开微信开发者工具,选择根目录下的 app.json 文件,由于 tabBar 主要用于页面间的切换,这里我们现在 pages 字段中创建好对应的页面信息:

app.json 中的 tabBar 字段和 pages 字段是同级的,所以在 app.json 中添加这个字段:

bash 复制代码
"tabBar": {
    "selectedColor": "#f3514f",
    "color": "#666",
    "borderStyle":"black",
    "position": "bottom",
    "list": [{
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "/assets/tabbar/index.png",
      "selectedIconPath": "/assets/tabbar/index-active.png"
    },
    {
      "pagePath": "pages/cate/cate",
      "text": "分类",
      "iconPath": "/assets/tabbar/cate.png",
      "selectedIconPath": "/assets/tabbar/cate-active.png"
    },
    {
      "pagePath": "pages/cart/cart",
      "text": "购物车",
      "iconPath": "/assets/tabbar/cart.png",
      "selectedIconPath": "/assets/tabbar/cart-active.png"
    },
    {
      "pagePath": "pages/profile/profile",
      "text": "我的",
      "iconPath": "/assets/tabbar/profile.png",
      "selectedIconPath": "/assets/tabbar/profile-active.png"
    }]
  }

参考视频:尚硅谷微信小程序开发教程

相关推荐
温暖小土1 小时前
ClickHouse vs Apache Doris:2026年实时OLAP数据库选型深度解析
数据库·数据仓库·clickhouse·apache
说私域2 小时前
基于AI智能名片链动2+1模式预约服务商城小程序的数据管理与系统集成研究
大数据·人工智能·小程序
说私域3 小时前
用户感知断裂与商业模式颠覆:AI智能名片链动2+1模式S2B2C商城小程序的破局之道
大数据·人工智能·小程序
小当家.1053 小时前
《Java操作Excel实战教程:Apache POI从入门到精通》
java·apache·excel
peachSoda73 小时前
uniapp开发小程序 使用scroll-view时左右滑动切换无法回到最左边的bug解决方案
小程序·uni-app
游戏开发爱好者84 小时前
如何在 Windows 环境下测试 iOS App,实时日志,CPU监控
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导64 小时前
基于微信小程序的社区医疗服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
fengGer的bugs4 小时前
微信小程序版「死了么APP」,它来了
微信小程序·小程序·死了么·死了么app
我的86呢!4 小时前
微信小程序蓝牙配网
微信小程序·小程序
花卷HJ5 小时前
【微信小程序】open-type=“contact“ 客服按钮样式无法设置?隐藏 button + label 触发完美解决
微信小程序·小程序·notepad++