小程序配置文件 —— 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"
    }]
  }

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

相关推荐
空中海8 小时前
微信小程序 - 03 工程实践层与综合 Demo
微信小程序·小程序·notepad++
优睿远行10 小时前
微信小程序云开发环境搭建与REST API混合架构实战
微信小程序·小程序
空中海11 小时前
微信小程序 - 02 基础概念层与核心能力层
微信小程序·小程序
DolphinScheduler社区11 小时前
Apache DolphinScheduler 与 Spring Cloud Data Flow:差异与优势解析
spring·spring cloud·apache·海豚调度·大数据工作流调度
游戏开发爱好者814 小时前
使用Fiddler设置HTTPS抓包诊断Power Query网络问题
android·ios·小程序·https·uni-app·iphone·webview
七月的冰红茶15 小时前
【开发工具】使用cursor实现点单小程序
小程序
码农客栈16 小时前
小程序学习(十八)之“骨架屏”
小程序
SeaTunnel17 小时前
Apache SeaTunnel 4 月有何新动作?连接器增强与 Zeta 稳定性提升等亮点速览
大数据·数据仓库·spark·apache·seatunnel
kyh100338112019 小时前
微信小程序摇骰子功能实现|含源码
微信小程序·小程序·摇骰子小游戏·摇色子源码
程序鉴定师1 天前
西安App开发推荐与业界认可的优秀实践
大数据·小程序