// 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>預(yù)覽</view> <image mode="widthFix" src="{{src}}"></image>
調(diào)試需要使用真機調(diào)試,微信開發(fā)者工具不支持照相機調(diào)試。
開發(fā)文檔地址 https://developers.weixin.qq.com/miniprogram/dev/component/camera.html
?
本文摘自 :https://blog.51cto.com/u