小程序框架學習2——(app.json)

2、app.json


(1)作用


  • app.json文件用來對微信小程序進行全局配置
  • 有以下五種配置(決定頁面文件的路徑pages、窗口表現window、設置網絡超時時間networkTimeout、設置tab按鈕tabBar、設置調試debug )
屬性 類型 必填 描述
pages String Array 設置頁面路徑
window Object 設置默認頁面的窗口表現
tabBar Object 設置底部 tab 的表現
networkTimeout Object 設置網絡超時時間
debug Boolean 設置是否開啓 debug 模式
  • 例子
{
"pages":[
"pages/index/index",
"pages/logs/logs",
"pages/me/me"
],
"window":{
"navigationBarBackgroundColor": "#000000",
"navigationBarTextStyle": "white",
"navigationBarTitleText": "師赴",
"backgroundColor": "#000",
"backgroundTextStyle": "light",
"enablePullDownRefresh": true,
"onReachBottomDistance":50
},
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首頁",
"iconPath": "/img/index_normal.png",
"selectedIconPath": "/img/index_select.png"
},{
"pagePath":"pages/logs/logs",
"text": "日誌",
"iconPath": "/img/index_normal.png",
"selectedIconPath": "/img/index_select.png"
},
{
"pagePath": "pages/me/me",
"text": "日誌",
"iconPath": "/img/index_normal.png",
"selectedIconPath": "/img/index_select.png"
}],
"color": "#000000",
"selectedColor": "#ff0000",
"backgroundColor": "#9900ff00",
"borderStyle": "black",
"position":"top"
},
"networkTimeout": {
"request": 60000,
"connectSocket": 60000,
"uploadFile": 60000,
"downloadFile": 60000
},
"debug":true
}

(2)pages

  • 接受一個數組,每一項都是字符串,來指定小程序由哪些頁面組成
  • 數組的第一項代表小程序的初始頁面
  • 小程序中新增/減少頁面,都需要對 pages 數組進行修改
  • 文件名不需要寫文件後綴,因爲框架會自動去尋找路徑下 .json, .js, .wxml, .wxss 四個文件進行整合

(3)window

  • 屬性
屬性 類型 默認值 描述
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


(4)tabBar


  • 當設置 position 爲 top 時,將不會顯示 icon
  • tabBar 中的 list 是一個數組,只能配置最少2個、最多5個 tab,tab 按數組的順序排序
  • tabBar屬性
屬性 類型 必填 默認值 描述
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 時,此參數無效

(5)networkTimeout


  • 可以設置各種網絡請求的超時時間
屬性 類型 必填 說明
request Number wx.request的超時時間,單位毫秒,默認爲:60000
connectSocket Number wx.connectSocket的超時時間,單位毫秒,默認爲:60000
uploadFile Number wx.uploadFile的超時時間,單位毫秒,默認爲:60000
downloadFile Number wx.downloadFile的超時時間,單位毫秒,默認爲:60000

(6)debug

  • 可以在開發者工具中開啓 debug 模式,在開發者工具的控制檯面板,調試信息以 info 的形式給出,其信息有Page的註冊,頁面路由,數據更新,事件觸發 。 可以幫助開發者快速定位一些常見的問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章