相机&图片
原来有个chooseImage接口,现在已经不维护了,改成chooseMedia。
chooseMedia(){
wx.chooseMedia({
count: 1,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success: (res) => {
if(res.tempFiles[0].fileType=="image"){
this.setData({
picSrc: res.tempFiles[0].tempFilePath
})
}else{
this.setData({
videoSrc: res.tempFiles[0].tempFilePath
})
}
}
})
}
- 选图片、视频,拍照、拍视频,都在wx.chooseMedia里面了。
- 可以配置可选数量、类型、来源。更多配置见官方文档。
- 一般都是有N个小方框,中间有个“十”字,可选可删除。现在网上有很多开源的组件,大家直接用就行了,本文就展示一下基本的用法。
- 实际项目中,选择或者拍摄成功后,都要搭配上传功能。现在应该都是上传OSS云服务了,我也没OSS的资源,就不演示了。
扫码
扫码结果:{{qrcode}}
scanQRCode(){
wx.scanCode({
onlyFromCamera:true,
success: (res) =>{
this.setData({
qrcode:res.result
})
}
})
}