// pages/list/list.js Page({ takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ src: res.tempImagePath }) } }) }, error(e) { console.log(e.detail) } })
<!--list.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>
调试需要使用真机调试,微信开发者工具不支持照相机调试。
开发文档地址 https://developers.weixin.qq.com/miniprogram/dev/component/camera.html
本文摘自 :https://blog.51cto.com/u