阅读量:118

设置小程序页面使用相机的案例:
在对应的wxml文件中添加以下代码:
<button type="primary"bindtap="takePhoto">拍照</button>
预览
在对应的js文件中添加以下代码:
// pages/headline/headline.js
Page({
takePhoto(){
const ctx=wx.createCameraContext()
ctx.takePhoto({
quality:'high',
success:(res)=>{
this.set.Data({
src:res.tempImagePath
})
}
})
},
error(e){
console.log(e.detail)
}
})