uni-app中pages.json详解

pages.json

pages.json 文件用来对 uni-app 进行全局配置,决定页面文件的路径、窗口表现、设置多 tab 等。

pages.json 配置项列表

globalStyle Object 否 设置默认页面的窗口表现
pages Object Array 是 设置页面路径及窗口表现
tabBar Object 否 设置底部 tab 的表现
condition Object 否 启动模式配置

以下是一个包含了所有配置选项的 pages.json :

{
	"pages": [
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "收银员",// 导航栏标题文字内容
				"backgroundTextStyle": "dark" ,//下拉 loading 的样式,仅支持 dark/light
				"enablePullDownRefresh":"false" ,//是否开启下拉刷新,详见页面相关事件处理函数
				"onReachBottomDistance":50 ,//页面上拉触底事件触发时距页面底部距离,单位为px 
				"backgroundColorTop":"#ffffff" ,//顶部窗口的背景色。 微信小程序且为 iOS
				"backgroundColorBottom":"#ffffff" ,//底部窗口的背景色。 微信小程序且为 iOS
			}
		},
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "收银员",// 导航栏标题文字内容
				"backgroundTextStyle": "dark" ,//下拉 loading 的样式,仅支持 dark/light
				"enablePullDownRefresh":"false" ,//是否开启下拉刷新,详见页面相关事件处理函数
				"onReachBottomDistance":50 ,//页面上拉触底事件触发时距页面底部距离,单位为px 
				"backgroundColorTop":"#ffffff" ,//顶部窗口的背景色。 微信小程序且为 iOS
				"backgroundColorBottom":"#ffffff" ,//底部窗口的背景色。 微信小程序且为 iOS
			}
			
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",//导航栏标题颜色,仅支持 black/white 
		"navigationBarTitleText": "uni-app",// 导航栏标题文字内容
		"navigationBarBackgroundColor": "#FFFFFF",//导航栏背景颜色
		"backgroundColor": "#F8F8F8",//窗口的背景色 微信小程序
		"navigationStyle":"default" ,//导航栏样式,仅支持 default/customm,开启 custom 后,所有窗口均无导航栏
	},
	 "tabBar": {
	    "color": "#7A7E83", //tab 上的文字默认颜色
	    "selectedColor": "#3cc51f", //tab 上的文字选中时的颜色
	    "borderStyle": "black", //tabbar 上边框的颜色,仅支持 black/white
	    "backgroundColor": "#ffffff", //tab 的背景色
		"position":"bottom", //可选值 bottom、top
	    "list": [{
	      "pagePath": "pages/component/index", //页面路径,必须在 pages 中先定义
	      "iconPath": "static/image/icon_component.png", //图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
	      "selectedIconPath": "static/image/icon_component_HL.png", //选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效
	      "text": "组件" //tab 上按钮文字
	    }, {
	      "pagePath": "pages/API/index",
	      "iconPath": "static/image/icon_API.png",
	      "selectedIconPath": "static/image/icon_API_HL.png",
	      "text": "接口"
	    }]
	  }
}

globalStyle
用于设置应用的状态栏、导航条、标题、窗口背景色等。

navigationBarBackgroundColor HexColor #000000 导航栏背景颜色 
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white 
navigationBarTitleText String  导航栏标题文字内容 
navigationStyle String default 导航栏样式,仅支持 default/custom。 
backgroundColor HexColor #ffffff 窗口的背景色 微信小程序

注意:navigationStyle 只在 pages.json->globalStyle 中设置生效。开启 custom 后,所有窗口均无导航栏。

pages
接收一个数组,来指定应用由哪些页面组成。每一项代表对应页面的信息,应用中新增/减少页面,都需要对 pages 数组进行修改。

文件名不需要写后缀,框架会自动寻找路径下的页面资源。

注意:pages节点的第一项为应用入口页(即首页)。

pages.style
用于设置每个页面的状态栏、导航条、标题、窗口背景色等。

navigationBarBackgroundColor HexColor #000000 导航栏背景颜色,如"#000000" 
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white 
navigationBarTitleText String  导航栏标题文字内容 
backgroundColor HexColor #ffffff 窗口的背景色 微信小程序
backgroundTextStyle String dark 下拉 loading 的样式,仅支持 dark/light 
enablePullDownRefresh Boolean false 是否开启下拉刷新,详见页面相关事件处理函数 
onReachBottomDistance Number 50 页面上拉触底事件触发时距页面底部距离,单位为px 
navigationStyle String default 导航栏样式,仅支持 default/custom。custom 模式可自定义导航栏,只保留右上角胶囊状的按钮。 微信小程序
backgroundColorTop String #ffffff 顶部窗口的背景色。 微信小程序且为 iOS
backgroundColorBottom String #ffffff 底部窗口的背景色。 微信小程序且为 iOS

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
list Array 是  tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
position String 否 bottom 可选值 bottom、top

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

pagePath String 是 页面路径,必须在 pages 中先定义
text String 是 tab 上按钮文字
iconPath String 否 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPath String 否 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

condition
启动模式配置,仅开发期间生效,用于模拟直达页面的场景,如:小程序转发后,用户点击所打开的页面。

属性说明:

current Number 是 当前激活的模式,list节点的索引值
list Array 是 启动模式列表
list说明:

name String 是 启动模式名称
path String 是 启动页面路径

query String 否 启动参数,可在页面的 onLoad 函数里获得
注意: 在5+app里真机运行可直接打开配置的页面,微信开发者工具里需要手动改变编译模式:
代码示例:

“condition”: { //模式配置,仅开发期间生效
“current”: 0, //当前激活的模式(list 的索引项)
“list”: [{
“name”: “swiper”, //模式名称
“path”: “pages/component/swiper/swiper”, //启动页面,必选
“query”: “interval=4000&autoplay=false” //启动参数,在页面的onLoad函数里面得到。
},
{
“name”: “test”,
“path”: “pages/component/switch/switch”
}
]
}

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值