媒体组件 camera
系统相机。扫码二维码功能,需升级微信客户端至6.7.3。需要用户授权 scope.camera。
device-position back 摄像头朝向后置
flash off 关闭闪光灯
binderror 用户不允许使用摄像头时触发
//camera.wxml
<camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<button type="primary" bindtap="takePhoto">拍照</button>
<view>预览</view>
<image mode="widthFix" src="{{src}}"></image>
//camera.js
Page({
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
})
},
error(e) {
console.log(e.detail)
}
})