
weChat
一、微信小程序
.js 腳本文件
.json 配置文件
.wxss 樣式表文件
二、文件結(jié)構(gòu)
主體組成:
- 必須放在項目根目錄
| 文件 | 說明 | 備注 |
|---|---|---|
| app.js | 小程序邏輯 | |
| app.json | 小程序公共設置 | |
| app.wxss | 小程序公共樣式表 | . |
頁面組成:
- 必須具有相同的路徑與文件名
| 文件 | 說明 | 備注 |
|---|---|---|
| js | 頁面邏輯 | |
| wxml | 頁面結(jié)構(gòu) | |
| wxss | 頁面樣式表 | |
| json | 頁面配置 | . |
三、配置
使用app.json文件來對微信小程序進行全局配置,決定頁面文件的路徑、窗口表現(xiàn)、設置網(wǎng)絡超時時間、設置多 tab 等。
app.json
| 字段 | 類型 | 必填 | 說明 | 備注 |
|---|---|---|---|---|
| pages | String Array | 是 | 頁面路徑 | |
| window | Object | 否 | 默認頁面的窗口 | |
| tabBar | Object | 否 | 底部tab | |
| networkTimeout | Object | 否 | 網(wǎng)絡超時時間 | |
| dubug | Boolean | 否 | 是否開啟debug模式 | . |
pages
指定頁面組成。
//1.每一項代表對應頁面的【路徑+文件名】信息
//2.數(shù)組的第一項代表小程序的初始頁面
//3.小程序中新增/減少頁面,都需要對 pages 數(shù)組進行修改
//4.文件名不需要寫文件后綴
{
"pages":[
"pages/index/index"
"pages/logs/logs"
]
}
window
設置小程序的狀態(tài)欄、導航條、標題、窗口背景色。
{
"window":{
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "微信接口功能演示",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
}
| 屬性 | 類型 | 默認值 | 說明 | 備注 |
|---|---|---|---|---|
| navigationBarBackgroundColor | HexColor | #000000 | 導航欄背景?色 | |
| navigationBarTextStyle | String | white | 導航欄標題樣式 | black/white |
| navigationBarTitleText | String | 導航欄標題 | ||
| backgroundColor | HexColor | #ffffff | 窗口背景顏色 | |
| backgroundTextStyle | String | dark | 下拉背景字體loading樣式 | dark/light |
| enablePullDownRefresh | Boolean | false | 是否開啟下拉刷新 | . |
tabBar
指定標簽欄組成,以及切換時顯示的頁面
頁面跳轉(zhuǎn)(wx.navigateTo)
頁面重定向(wx.redirectTo)
//只能配置最少2個、最多5個 tab
"tabBar":{
"color": "#ffffff",
"selectedColor": "#ffffff",
"backgroundColor": "#ffffff",
"borderStyle": "black",
"list": [{
"pagePath": "pages/index/index",
"text": "首頁",
"iconPath": "",
"selectedIconPath": ""
},{
"pagePath": "pages/logs/logs",
"text": "我的",
"iconPath": "",
"selectedIconPath": ""
}],
"position": "bottom"
}
| 屬性 | 類型 | 必填 | 默認值 | 說明 | 備注 |
|---|---|---|---|---|---|
| color | HexColor | 是 | 標題默認顏色 | ||
| selectedColor | HexColor | 是 | 標題選中顏色 | ||
| backgroundColor | HexColor | 是 | 背景色 | ||
| borderStyle | String | 否 | black | 邊框的顏色 | black/white |
| list | Array | 是 | 標簽配置 | 最少2個、最多5個 | |
| position | String | 否 | bottom | 可選值 bottom、top | bottom/top |
list
數(shù)組中的每個項都是一個對象
| 屬性 | 類型 | 必填 | 說明 | 備注 |
|---|---|---|---|---|
| pagePath | String | 是 | 頁面路徑 | |
| text | String | 是 | 標題 | |
| iconPath | String | 是 | 默認圖片 | 40KB, 81x81px |
| selectedIconPath | String | 是 | 選中圖片 | 40KB, 81x81px |
networkTimeout
設置網(wǎng)絡請求的超時時間
| 屬性 | 類型 | 必填 | 默認值 | 說明 | 備注 |
|---|---|---|---|---|---|
| request | Number | 否 | 60000 | wx.request 超時時間 | 毫秒 |
| connectSocket | Number | 否 | 60000 | wx.connectSocket 超時時間 | 毫秒 |
| uploadFile | Number | 否 | 60000 | wx.uploadFile 超時時間 | 毫秒 |
| downloadFile | Number | 否 | 60000 | wx.downloadFile 超時時間 | 毫秒 |
debug
設置開發(fā)者工具中開啟 debug 模式
Page的注冊,頁面路由,數(shù)據(jù)更新,事件觸發(fā)
page.json
設置本頁面的窗口
{
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "微信接口功能演示",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
| 屬性 | 類型 | 默認值 | 說明 | 備注 |
|---|---|---|---|---|
| navigationBarBackgroundColor | HexColor | # 000000 | 導航欄背景顏色 | |
| navigationBarTextStyle | String | white | 導航欄標題顏色 | black/white |
| navigationBarTitleText | String | 導航欄標題文字內(nèi)容 | ||
| backgroundColor | HexColor | #ffffff | 窗口的背景色 | |
| backgroundTextStyle | String | dark | 下拉背景字體、loading 圖的樣式 | dark/light |
| enablePullDownRefresh | Boolean | false | 是否開啟下拉刷新 | |
| disableScroll | Boolean | false | 頁面整體不能上下滾動 | 只在 page.json 中有效 |