W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
app.json是一個(gè)用來對(duì)頭條小程序進(jìn)行全局配置的文件,用來配置頁面的路徑,窗口樣式表現(xiàn)等。
app.json的配置選項(xiàng)如下:
{
"pages": [
"pages/index/index",
"pages/logs/index"
],
"window": {
"navigationBarTitleText": "Demo"
},
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首頁"
}, {
"pagePath": "pages/logs/logs",
"text": "日志"
}]
}
}
屬性 | 類型 | 必填 | 描述 | 最低版本 |
---|---|---|---|---|
pages | String Array | 是 | 配置頁面路徑 | |
window | Object | 否 | 配置默認(rèn)頁面的窗口表現(xiàn) | |
tabBar | Object | 否 | 配置底部 tab 的表現(xiàn) | |
navigateToMiniProgramAppIdList | Array | 否 | 需要跳轉(zhuǎn)的小程序列表,相關(guān)api見tt.navigateToMiniProgram | 1.15.0 |
這個(gè)字段用于配置小程序用到的所有頁面路徑,配置每項(xiàng)是 路徑 + 文件名 這個(gè)結(jié)構(gòu)。配置項(xiàng)的第一個(gè)頁面路徑就是小程序啟動(dòng)展示的第一個(gè)頁面。
需要注意:保證單個(gè)頁面的.json, .js, .ttml, .ttss資源都放在每個(gè)頁面路徑的首層
如開發(fā)目錄如下:
|____app.ttss
|____app.json
|____project.config.json
|____pages
| |____index
| | |____index.js
| | |____index.json
| | |____index.ttml
| | |____index.ttss
|____app.js
那么app.json應(yīng)該這樣配置:
{
"pages":[
"pages/index/index"
]
}
這個(gè)字段用于設(shè)置小程序的狀態(tài)欄、導(dǎo)航條、標(biāo)題、窗口背景色。
屬性 | 類型 | 默認(rèn)值 | 描述 |
---|---|---|---|
navigationBarBackgroundColor | HexColor | #000000 | 導(dǎo)航欄背景顏色,如"#000000" |
navigationBarTextStyle | String | white | 導(dǎo)航欄標(biāo)題顏色,僅支持 black/white |
navigationBarTitleText | String | 導(dǎo)航欄標(biāo)題文字內(nèi)容 | |
navigationStyle | String | default | 導(dǎo)航欄樣式,僅支持 default/custom。custom 模式可自定義導(dǎo)航欄,只保留右上角膠囊狀的按鈕 |
backgroundColor | HexColor | #ffffff | 窗口的背景色 |
backgroundTextStyle | String | dark | 下拉 loading 的樣式,僅支持 dark/light |
backgroundColorTop | String | #ffffff | 頂部窗口的背景色,僅 iOS 支持 |
backgroundColorBottom | String | #ffffff | 底部窗口的背景色,僅 iOS 支持 |
enablePullDownRefresh | Boolean | false | 是否開啟下拉刷新,詳見頁面相關(guān)事件處理函數(shù) |
onReachBottomDistance | Number | 50 | 頁面上拉觸底事件觸發(fā)時(shí)距頁面底部距離,單位為px |
如果你的小程序包含多個(gè)tab(客戶端窗口的底部或頂部有 tab 欄可以切換頁面),可以通過 tabBar 配置項(xiàng)指定 tab 欄的表現(xiàn),以及 tab 切換時(shí)顯示的對(duì)應(yīng)頁面。比如設(shè)置tab展示標(biāo)題和tab顏色等。
屬性 | 類型 | 必填 | 默認(rèn)值 | 描述 |
---|---|---|---|---|
color | HexColor | 是 | tab 上的文字默認(rèn)顏色 | |
selectedColor | HexColor | 是 | tab 上的文字選中時(shí)的顏色 | |
backgroundColor | HexColor | 是 | tab 的背景色 | |
borderStyle | String | 否 | black | tabbar上邊框的顏色, 僅支持 black/white |
list | Array | 是 | tab 的列表,詳見 list 屬性說明,最少2個(gè)、最多5個(gè) tab |
其中 list 接受一個(gè)數(shù)組,數(shù)組中的每個(gè)項(xiàng)都是一個(gè)對(duì)象,其屬性值如下:
屬性 | 類型 | 必填 | 描述 |
---|---|---|---|
pagePath | String | 是 | 頁面路徑,必須在 pages 中先定義 |
text | String | 是 | tab 上按鈕文字 |
iconPath | String | 否 | 圖片路徑,icon 大小限制為40kb,建議尺寸為 81px * 81px,當(dāng) postion 為 top 時(shí),此參數(shù)無效,不支持網(wǎng)絡(luò)圖片 |
selectedIconPath | String | 否 | 選中時(shí)的圖片路徑,icon 大小限制為40kb,建議尺寸為 81px * 81px ,當(dāng) postion 為 top 時(shí),此參數(shù)無效 |
當(dāng)小程序需要使用tt.navigateToMiniProgram接口跳轉(zhuǎn)到其他小程序時(shí),需要先在配置文件中聲明需要跳轉(zhuǎn)的小程序appId列表,最多允許填寫 10 個(gè)。
頭條小程序的每一個(gè)頁面的窗口表現(xiàn)也可以通過頁面目錄下的.json文件進(jìn)行配置,這個(gè)頁面的獨(dú)立配置會(huì)比 app.json 要簡單;
如果 app.json 的 window 字段里面配置了某個(gè)頁面的窗口樣式,同時(shí)該頁面也在自己的 .json文件中做了對(duì)應(yīng)字段的配置的話,框架會(huì)優(yōu)先采用頁面里面的 .json 相應(yīng)配置項(xiàng)。
具體的配置字段如下:
屬性 | 類型 | 默認(rèn)值 | 描述 |
---|---|---|---|
navigationBarBackgroundColor | HexColor | #000000 | 導(dǎo)航欄背景顏色,如"#000000" |
navigationBarTextStyle | String | white | 導(dǎo)航欄標(biāo)題顏色,僅支持 black/white |
navigationBarTitleText | String | 導(dǎo)航欄標(biāo)題文字內(nèi)容 | |
navigationStyle | String | default | 導(dǎo)航欄樣式,僅支持 default/custom。custom 模式可自定義導(dǎo)航欄,只保留右上角膠囊狀的按鈕 |
backgroundColor | HexColor | #ffffff | 窗口的背景色 |
backgroundTextStyle | String | dark | 下拉 loading 的樣式,僅支持 dark/light |
enablePullDownRefresh | Boolean | false | 是否開啟下拉刷新,詳見頁面相關(guān)事件處理函數(shù)。 |
disableScroll | Boolean | false | 設(shè)置為 true 則頁面整體不能上下滾動(dòng);只在 page.json 中有效,無法在 app.json 中設(shè)置該項(xiàng) |
disableSwipeBack | Boolean | false | 禁止頁面右滑手勢返回 |
onReachBottomDistance | Number | 50 | 頁面上拉觸底事件觸發(fā)時(shí)距頁面底部距離,單位為px |
usingComponents | Object | 自定義組件配置 |
例子:
{
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "頭條接口功能演示",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: