微信小程序的API开发
1,请求服务器数据
wx.request的使用
了解http协议
wx.request:发起 HTTPS 网络请求
里面包括属性、参数和函数 ,都一起包裹着写在js文件中
示例:
wx.request({
url: 'test.php',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res.data)
}
})
属性:url(开发者服务器接口地址)
data(请求的参数)
header(设置请求的 header 设置http里的一些请求属性)
method(HTTP 请求方法)
success(接口调用成功的回调函数)
fail(接口调用失败的回调函数)
图片选择与调用微信拍照
wx.chooseimage 选择图片
照相机拍照
API也是写在绑定事件里的
wx.chooseimage : 从本地相册选择图片或使用相机拍照
示例:
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['', 'camera'],
success (res) {
<