字節(jié)跳動(dòng)小程序開發(fā)框架全局配置

2019-07-25 10:51 更新

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": "日志"
    }]
  }
}

配置項(xiàng)說明


屬性 類型 必填 描述 最低版本
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

pages

這個(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"
  ]
}

window

這個(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

tabBar

如果你的小程序包含多個(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è)。

page.json


頭條小程序的每一個(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"
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)