博客
关于我
uni-app(4)— 配置tabbar
阅读量:502 次
发布时间:2019-03-07

本文共 2826 字,大约阅读时间需要 9 分钟。

此文为uni-app总结笔记(4)— 配置tabbar

如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页。

Tips

  • 当设置 position 为 top 时,将不会显示 icon
  • tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。

常用属性说明:

属性 类型 必填 默认值 描述 平台差异说明
color HexColor tab 上的文字默认颜色
selectedColor HexColor tab 上的文字选中时的颜色
backgroundColor HexColor tab 的背景色
borderStyle String black tabbar 上边框的颜色,仅支持 black/white App 2.3.4+ 支持其他颜色值
list Array tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
position String bottom 可选值 bottom、top top 值仅微信小程序支持

其中 list 接收一个数组,数组中的每个项都是一个对象,其属性值如下:

属性 类型 必填 说明
pagePath String 页面路径,必须在 pages 中先定义
text String tab 上按钮文字,在 5+APP 和 H5 平台为非必填。例如中间可放一个没有文字的+号图标
iconPath String 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片,不支持字体图标
selectedIconPath String 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

示例代码:

"tabBar": {   		"list": [			{   				"text": "首页",				"pagePath":"pages/index/index",				"iconPath":"static/tabs/home.png",				"selectedIconPath":"static/tabs/home-active.png"			},			{   				"text": "信息",				"pagePath":"pages/message/message",				"iconPath":"static/tabs/message.png",				"selectedIconPath":"static/tabs/message-active.png"			},			{   				"text": "我们",				"pagePath":"pages/contact/contact",				"iconPath":"static/tabs/contact.png",				"selectedIconPath":"static/tabs/contact-active.png"			}		]	}

注意:

通过官网可知,pages 和 tabbar 同级。
在这里插入图片描述
为tabBar单独设置样式:

  1. “color”: 颜色
  2. “selectedColor”: 选中颜色
  3. “backgroundColor”: 背景颜色
  4. “borderStyle”: 上边框颜色( 仅支持 black 和 white )
  5. “position”: tabbar位置(可选值 bottom、top ,top 值仅微信小程序支持 )

效果展示

首页状态:
在这里插入图片描述
信息页状态
在这里插入图片描述
联系我们页面:
在这里插入图片描述
icon展示:
在这里插入图片描述

完整的page.json文件代码:

{   	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages		{   			"path": "pages/message/message",			"style": {   				"navigationBarTitleText":"信息页",				"navigationBarBackgroundColor":"#FF6666",				"h5": {   					"pullToRefresh": {   						"color":"#007AFF"					}				}			}		},		{   			"path": "pages/index/index"		},	    {   			"path":"pages/contact/contact"		}    ],	"globalStyle": {   		"navigationBarTextStyle": "white",		"navigationBarTitleText": "你好呀",		"navigationBarBackgroundColor": "#66CCCC",		"enablePullDownRefresh": true,		"backgroundColor": "#CCFFFF"	},	"tabBar": {   		"color":"#4CD964",		"selectedColor":"#DD524D",		"backgroundColor":"#FFFFFF",		"borderStyle":"black",		"position":"bottom",		"list": [			{   				"text": "首页",				"pagePath": "pages/index/index",				"iconPath":"static/tabs/home.png",				"selectedIconPath":"static/tabs/home-active.png"			},			{   				"text":"信息",				"pagePath":"pages/message/message",				"iconPath":"static/tabs/message.png",				"selectedIconPath":"static/tabs/message-active.png"			},			{   				"text":"我们",				"pagePath":"pages/contact/contact",				"iconPath":"static/tabs/contact.png",				"selectedIconPath":"static/tabs/contact-active.png"			}		]	}}

转载地址:http://wypcz.baihongyu.com/

你可能感兴趣的文章
nativescript(angular2)——ListView组件
查看>>
NativeWindow_01
查看>>
Native方式运行Fabric(非Docker方式)
查看>>
Nature | 电子学“超构器件”, 从零基础到精通,收藏这篇就够了!
查看>>
Nature和Science同时报道,新疆出土四千年前遗骸完成DNA测序,证实并非移民而是土著...
查看>>
Nature封面:只低一毫米,时间也会变慢!叶军团队首次在毫米尺度验证广义相对论...
查看>>
Nat、端口映射、内网穿透有什么区别?
查看>>
Nat、端口映射、内网穿透有什么区别?
查看>>
nat打洞原理和实现
查看>>
NAT技术
查看>>
NAT模式/路由模式/全路由模式 (转)
查看>>
NAT模式下虚拟机centOs和主机ping不通解决方法
查看>>
NAT的两种模式SNAT和DNAT,到底有啥区别?
查看>>
NAT的全然分析及其UDP穿透的全然解决方式
查看>>
NAT类型与NAT模型详解
查看>>
NAT网络地址转换配置实战
查看>>
NAT网络地址转换配置详解
查看>>
navbar navbar-inverse 导航条设置颜色
查看>>
Navicat for MySQL 命令列 执行SQL语句 历史日志
查看>>
Navicat for MySQL 查看BLOB字段内容
查看>>