你不会还不知道微信小程序如何全局配置tabBar吧——tabBar简介

336 阅读2分钟

我正在参与掘金创作者训练营第6期,点击了解活动详情

介绍

什么是tabBar?

tabBar是微信小程序的导航栏配置,当小程序是一个多 tab 页面应用时,可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面,用于小程序多页面的快速切换。 微信小程序tabBar分为两种:

顶部tabBar和底部tabBar。

如图:

顶部tabBar

微信截图_20220828092355.png

底部tabBar

微信截图_20220828092522.png

全局配置tabBar

1.tabBar组成部分

微信图片编辑_20220828100826.jpg

tabBar由六部分组成

① backgroundColor:tabBar 的背景色

② selectedIconPath:选中时的图片路径

③ borderStyle:tabBar 上边框的颜色

④ iconPath:未选中时的图片路径

⑤ selectedColor:tab 上的文字选中时的颜色

⑥ color:tab 上文字的未选中时的颜色

tabBar的属性

属性类型必填默认值描述
positionStringbottomtabBar 的位置,仅支持 bottom/top
borderStyleStringblacktabBar 上边框的颜色,仅支持 black/white
colorHexColortab 上文字的未选中时的颜色(仅支持十六进制颜色)
selectedColorHexColortab 上的文字选中时的颜色(仅支持十六进制颜色)
backgroundColorHexColortabBar 的背景色
listArraytab 页签的列表,最少 2 个,最多 5 个 tab
custombooleanfalse用于自定义tabBar

特别注意:

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

list属性

属性类型必填描述
pagePathString页面路径,必须现在pages中先定义
textStringtab按钮上的文字
iconPathString图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。(当 position 为 top 时,不显示 icon。)
selectedIconPathSring选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。(当 position 为 top 时,不显示 icon。)