先上结论:在wxml页面对src的值进行修改,即<image src='{{src}}'。
首先,在CameraContext.takePhoto(Object object)接口中,成功函数返回的res.tempImagePath是string类型返回值。
takePhoto(){
const ctx=wx.createCameraContext()
ctx.takePhoto({
quality:'high',//图片质量->高
success:(res)=>{
//console.log(res.tempImagePath)
this.setData({
src:res.tempImagePath,
isShowPic:true,
},()=>{
//this.getFaceInfo()//成功的回调函数
this.getFaceInfo()
})
},
fail:()=>{
console.log('拍照失败!')
this.setData({
src:''
})
}
})
},
所以在wxml中需要对传值进行处理
//face_index.js
data: {
//窗口可用的高度
wh:0,
//摄像头的朝向
position:'front',
//照片的路径
src:'',
isShowPic:false,
//人脸信息
faceinfo:null
},
//face_index.wxml
<view wx:else>
<image src='{{src}}'
style='width: 100%; height:{{wh}}px;display: block;' mode='aspectFill'></image> <!--注意新旧接口,src-->
<button type='primary' class='rechoose' bindtap='rechoose'>重选照片</button>
</view>
其中,src应该是“src='{{src}}'”