

1)用户使用的便捷性
普通app我们的使用过程:下载-打开-注册-使用
小程序:打开(扫码/搜索)- 使用
2)小程序的用户体验,远远高于公众号和h5
3)释放手机内存空间,小程序不需要安装,而且有规定的大小(目前不能超过8M)
4)让手机界面更加简洁
1)由于小程序的各种好处,使用小程序的用户越来越多
2)从公司的角度,有自己的小程序越来越重要
3)为了给用户带来更加便捷的使用体验,需要开发一款对应的小程序



小程序的版本追踪:https://developers.weixin.qq.com/miniprogram/dev/framework/release/

1)申请AppID
微信公众平台:https://mp.weixin.qq.com
开发工具选择:官方微信web开发者工具,VSCode



<view>hello {{name}}view>
<view>我的年龄:{{age}}view>
<view wx:for="{{students}}">{{item.name}}view>
<view>当前计数:{{counter}}view>
<button size="mini" bindtap="handleBtnClick">+button>

小程序的很多开发需求被规定在了配置文件中
为什么要这么做呢?
常见的配置文件有哪些?
1)project.config.json:项目配置文件,比如项目名称,appid等
(https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html)
2)sitemap.json : 小程序搜索相关
(https://developers.weixin.qq.com/miniprogram/framework/sitemap.html)
3)app.json:全局配置(重要)
https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html

window配置
"navigationBarBackgroundColor": "#ff5777", //配置导航栏背景颜色
"navigationBarTextStyle": "white", //配置导航栏字体颜色
"navigationBarTitleText": "小晨的商店" //配置小程序标题
tabBar配置:
"selectedColor": "#ff5777", //tabBar字体的背景颜色
"list": [{ //tabBar的每个item
"pagePath": "pages/home/home",
"text": "首页",
"iconPath": "/assets/tabbar/shop.png", //item图标
"selectedIconPath": "/assets/tabbar/shop_active.png" //被选中时的图标
},{
"pagePath": "pages/about/about",
"text": "分类",
"iconPath": "/assets/tabbar/my.png",
"selectedIconPath": "/assets/tabbar/my_active.png"
}]
4)page.json:页面配置
页面配置会覆盖app.json中的全局配置





每个小程序都需要在app.js中调用App方法注册小程序
App({
//当小程序初始化完成时
onLaunch: function () {
console.log("小程序初始化完成了")
wx.getUserInfo({ //wx开头的都是微信提供给我们的一些系统api
success: function(res) {
console.info(res);
}
})
},
//小程序界面显示出来后
onShow: function (options) {
},
//小程序界面被隐藏时
onHide: function () {
},
//当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
onError: function (msg) {
}
})
【注意】wx.getUserInfo 将要废弃,通过下面的方式获取用户信息

1)注册App时,我们一般会做什么?
2)小程序的后台存活时间
2小时
3)小程序的打开场景
https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
4)如何确定小程序的打开场景
在APP.js中的onLaunch和onShow声明周期回调函数中会有options参数,其中有scene值(代表着小程序的进入场景)
App({
onLaunch: function (options) {
//options中有小程序的打开场景
},
onShow: function (options) {
//options中有小程序的打开场景
},
onHide: function () {
},
onError: function (msg) {
}
})
https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html
1)在生命周期中发送网络请求,从服务器获取数据
2)初始化一些数据
3)监听wxml中的相关的一些事件
4)其他的一些监听(比如页面的滚动,上拉刷新,下拉加载等)

https://developers.weixin.qq.com/miniprogram/dev/component/text.html
Text 组件用于显示文本,类似于span标签,是行内元素
<text>hello 小程序text>
<text selectable="{{true}}">小晨要努力变强text>
<text selectable>小晨要努力变强\ntext>
<text>小晨要努 力变强text>
<text space="nbsp">小晨要努 力变强text>
<text space="ensp">小晨要努 力变强text>
<text space="emsp">小晨要努 力变强text>
https://developers.weixin.qq.com/miniprogram/dev/component/button.html
<button>注册button>
<button size="mini" type="warn">注册button>
https://developers.weixin.qq.com/miniprogram/dev/component/view.html
视图组价你:块级元素,独占一行,通常用作容器组件
https://developers.weixin.qq.com/miniprogram/dev/component/image.html
image组件用于显示图片
comfirm-type: 设置键盘右下角按钮的文字
scroll-view 可以实现具备滚动,常见属性如下:
<scroll-view class="container1" scroll-x>
<view wx:for="{{10}}" class="item1">{{item}}view>
scroll-view>
<scroll-view class="container1" scroll-y>
<view wx:for="{{10}}" class="item1">{{item}}view>
scroll-view>
所有wxml组件都支持的属性称为共同属性,有如下共同属性
