微信小程序全局配置tabBar

本文详细介绍了微信小程序中TabBar的配置和使用,包括底部和顶部TabBar的区别,配置项说明,以及一个实现三个页面切换的实例。通过全局配置文件展示了如何设置TabBar的各个元素,如页面路径、文字和图标。同时,强调了TabBar的限制,如最少2个、最多5个tab页签,以及顶部TabBar不显示icon等规则。
摘要由CSDN通过智能技术生成

微信小程序全局配置tabBar

什么是tabBar?

tabBar 是移动端应用常见的页面效果,用于实现多页面的快速切换。小程序中通常将其分为:

  • 底部 tabBar
  • 顶部 tabBar

注意:
tabBar中只能配置最少 2 个、最多 5 个 tab 页签
当渲染顶部 tabBar 时,不显示 icon,只显示文本

tabBar 节点的配置项

在这里插入图片描述

每个 tab 项的配置选项

在这里插入图片描述

实现案例

实现效果

实现了三个页面之间的互相切换,和tabBar之间图标选中效果之间的切换。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

全局配置

目录结构如下
在这里插入图片描述
整个案例的页面配置项如下

"pages": [
    "pages/index/index",
    "pages/list/list",
    "pages/message/message",
    "pages/logs/logs"
  ],

之后我们只需要在全局配置中完成tabBar的配置,即可完成页面之间切换的效果。

"tabBar": {
    "list": [
      {
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "/images/home.png",
      "selectedIconPath": "/images/home-active.png"
    },{
      "pagePath": "pages/list/list",
      "text": "列表",
      "iconPath": "/images/contact.png",
      "selectedIconPath": "/images/contact-active.png"
    },{
      "pagePath": "pages/message/message",
      "text": "消息",
      "iconPath": "/images/message.png",
      "selectedIconPath": "/images/message-active.png"
    }
  ]
  },

全局配置文件

{
  "pages": [
    "pages/index/index",
    "pages/list/list",
    "pages/message/message",
    "pages/logs/logs"
  ],
  "window": {
    "backgroundTextStyle": "dark",
    "navigationBarBackgroundColor": "#eee",
    "navigationBarTitleText": "小旭",
    "navigationBarTextStyle": "black",
    "enablePullDownRefresh": true,
    "backgroundColor": "#efefef"
  },
  "tabBar": {
    "list": [
      {
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "/images/home.png",
      "selectedIconPath": "/images/home-active.png"
    },{
      "pagePath": "pages/list/list",
      "text": "列表",
      "iconPath": "/images/contact.png",
      "selectedIconPath": "/images/contact-active.png"
    },{
      "pagePath": "pages/message/message",
      "text": "消息",
      "iconPath": "/images/message.png",
      "selectedIconPath": "/images/message-active.png"
    }
  ]
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json",
  "lazyCodeLoading": "requiredComponents"
  
 
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程序小旭

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

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

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

打赏作者

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

抵扣说明:

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

余额充值