2019年12月突然爆发的新型冠状病毒肺炎,使得本应该上班上课的人们留着在家,带着学习的热情,我就想学习学习小程序开发吧。
话不多说,要想学好一门技术,首先就是给自己制定计划:
1. 每天自行整理学习笔记。
2. 任务作业定时定量。
3. 调整好心态。
4. 多和前辈保持沟通。
5. 培养看官方文档的能力。([微信小程序开发文档](https://developers.weixin.qq.com/miniprogram/dev/framework/))
首先,跟着文档的步骤,创建自己的小程序账号,得到属于自己的APPID,接着下载微信开发者工具,至此正式开始了我的小程序开发之旅。
接着,创建一个新项目,了解项目的结构,配置小程序,将组件中的常用组件尝试使用。
在此,我想讲一下我对配置小程序的感想,总的来说,小程序分为全局配置、页面配置和sitemap配置。
## 全局配置
全局配置需要在项目中的 app.json 文件进行全局配置
属性 | 类型 | 必填 | 描述 |
---|---|---|---|
pages | Array | 是 | 页面路径列表 、首项配置的路径会被当成首页 |
window | Object | 否 | 全局的默认窗口表现。用于设置状态栏、导航条、标题、窗口背景色等等 |
tabBar | Object | 否 | 底部 tab栏的表现。好比底部或是顶部的导航栏 |
networkTimeout | Object | 否 | 设置网络请求超时时间 |
permission | Object | 否 | 用于小程序接口权限相关设置 |
navigateToMiniProgramAppIdList | str ing[] | 否 | 用于跳转的小程序列表,在此声明需要跳转的小程序 appId 列表,最多允许填写10个。 |
usingComponents | Object | 否 | 用于全局自定义组件的配置 |
sitemapLocation | string | 是 | 用于指明sitemap.json文件的位置 |
在官方文档还有更多的配置项。
1.1、pages
用于指定小程序的页面路径(含文件名) ,小程序中新增/减少页面,都需要对 pages 数组 进行修改。直接在pages选项中写页面路径,即可创建相应的页面文件。
1.2 window
用于设置小程序的状态栏、导航条、标题、窗口背景色
属性 | 类型 | 描述 |
---|---|---|
navigationBarBackgroundColor | HexColor | 设置导航栏的背景颜色,如 #ff6666 |
navigationBarTextStyle | string | 用于设置导航栏标题颜色,但仅支持 black / white两种颜色 |
navigationBarTitleText | string | 用于设置导航栏标题文字内容 |
navigationStyle | string | 导航栏样式,有default默认样式和custom自定义导航栏两种选择 |
backgroundColor | HexColor | 窗口的背景色 |
backgroundTextStyle | string | 下拉时loading的样式,仅支持 dark / light两种选择 |
enablePullDownRefresh | boolean | 是否开启全局的下拉刷新,默认是false |
onReachBottomDistance | number | 页面上拉触底事件触发时距页面底部距离,单位为 px |
pageOrientation | string | 屏幕旋转设置,支持 auto / portrait / landscape。默认是portr ait |
1.3tabBar
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。
属性 | 类型 | 描述 |
---|---|---|
color | HexColor | 文字默认颜色,仅支持十六进制颜色 |
selectedColor | HexColor | 文字选中时的颜色,仅支持十 六进制颜色 |
backgroundColor | HexColor | tabBar的背景色,仅支持十六进制颜色 |
borderStyle | string | 设置tabBar上边框的颜色, 仅支持 black / white |
list | Array | tabBar 的列表, 最少 2 个、最多 5 个 |
position | string | 设置tabBar的位置,仅支持 bottom / top |
custom | boolean | 用于自定义 tabBar |
list的配置
属性 | 类型 | 描述 |
---|---|---|
pagePath | string | 设置tab页面路径,必须在 pages中先定义 |
text | string | 设置tab上按钮的文字 |
iconPath | string | 默认时的图片路径,建议尺寸为 81px * 81px,不支持网络图片。当 position 为 top 时,不显示 icon。 |
selectedIconPath | string | 选中时的图片路径,建议尺寸为 81px * 81px,不支持网络图片。当 position 为 top 时,不显示 icon。 |
1.4 networkTimeout
各类网络请求的超时时间,单位均为毫秒。默认的值都为60000毫秒
属性 | 类型 | 描述 |
---|---|---|
request | number | 设置wx.request 的超时时间 |
connectSocket | number | 设置wx.connectSocket的超时时间 |
uploadFile | number | 设置wx.uploadFile的超时时间 |
downloadFi le | number | 设置wx.downloadFile的超时时间 |
在官方文档中还有很多的配置项,我会不断的学习的。
最后,贴上我的app。json 全局配置
{
"pages": [
"pages/home/home",
"pages/kind/kind",
"pages/cart/cart",
"pages/user/user"
],
"window": {
"navigationBarBackgroundColor": "#ff5f5f",
"navigationBarTextStyle": "white",
"navigationBarTitleText": "Holle Word",
"backgroundColor": "#000",
"backgroundTextStyle": "dark",
"backgroundColorTop": "#0f0",
"pageOrientation": "auto"
},
"tabBar": {
"color": "#333",
"selectedColor": "#e4393c",
"backgroundColor":"#efefef",
"borderStyle":"white",
"list":[{
"pagePath":"pages/home/home",
"iconPath":"resource/home.png",
"selectedIconPath":"resource/home_active.png",
"text":"首页"
},{
"pagePath":"pages/kind/kind",
"iconPath": "resource/kind.png",
"selectedIconPath": "resource/kind_active.png",
"text":"分类"
},{
"pagePath": "pages/cart/cart",
"iconPath": "resource/cart.png",
"selectedIconPath": "resource/cart_active.png",
"text": "购物车"
},{
"pagePath": "pages/user/user",
"iconPath": "resource/user.png",
"selectedIconPath": "resource/user_active.png",
"text": "我的"
}
]
},
"networkTimeout":{
"request":4500,
"connectSocket":4500,
"uploadFile":4500,
"downloadFile":4500
},
"permission":{
"scope.userLocation":{
"desc":"小程序获取位置信息展示"
}
},
"navigateToMiniProgramAppIdList":[ ],
"usingComponents": { },
"sitemapLocation": "sitemap.json",
"debug":false
}