版权声明:https://blog.csdn.net/qq_37949737?assign_skin=skin-ink https://blog.csdn.net/qq_37949737/article/details/86639183
tabBar
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。
属性 | 类型 | 必填 | 默认值 | 描述 | 最低版本 |
---|---|---|---|---|---|
color | HexColor | 是 | tab 上的文字默认颜色,仅支持十六进制颜色 | ||
selectedColor | HexColor | 是 | tab 上的文字选中时的颜色,仅支持十六进制颜色 | ||
backgroundColor | HexColor | 是 | tab 的背景色,仅支持十六进制颜色 | ||
borderStyle | String | 否 | black | tabbar上边框的颜色, 仅支持 black / white |
|
list | Array | 是 | tab 的列表,详见 list 属性说明,最少2个、最多5个 tab |
||
position | String | 否 | bottom | tabBar的位置,仅支持 bottom / top |
|
custom | Boolean | 否 | false | 自定义 tabBar | 2.5.0 |
其中 list 接受一个数组,只能配置最少 2 个、最多 5 个 tab。tab 按数组的顺序排序,每个项都是一个对象,其属性值如下:
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
pagePath | String | 是 | 页面路径,必须在 pages 中先定义 |
text | String | 是 | tab 上按钮文字 |
iconPath | String | 否 | 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,不支持网络图片。 当 postion 为 top 时,不显示 icon。 |
selectedIconPath | String | 否 | 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,不支持网络图片。 当 postion 为 top 时,不显示 icon。 |
实例代码如下:
"tabBar": {
"color": "#e0e0e0", //tabbar选项文字的默认颜色
"selectedColor": "#ff0000", //tabbar选项选中文字的颜色
"backgroundColor": "#cccccc", //tabbar的背景颜色
"borderStyle": "black", //tabbar上边框的颜色 仅支持 black / white 默认是black
"position": "bottom", //tabbar的位置 仅支持 bottom / top 默认是bottom
"list": [ //list是tab 的列表, list数组里面要最少2个、最多5个对象。
{
"pagePath": "pages/index/index",//跳转页面的路径
"text": "首页", //tabbar选项的文字
"iconPath": "pages/images/index.jpg", //tabbar选项的图片
"selectedIconPath": "pages/images/index_active.jpg" //tabbar选项选中的图片
},
{
"pagePath": "pages/classification/classification",
"text": "分类",
"iconPath": "pages/images/classification.jpg",
"selectedIconPath": "pages/images/classification_active.jpg"
},
{
"pagePath": "pages/cat/cat",
"text": "购物车",
"iconPath": "pages/images/cat.jpg",
"selectedIconPath": "pages/images/cat_active.jpg"
},
{
"pagePath": "pages/my/my",
"text": "我的",
"iconPath": "pages/images/my.jpg",
"selectedIconPath": "pages/images/my_active.jpg"
}
]
}