.wxml
<image class="camera-style" src="{{srcurl}}"></image>
<camera class="camera-style" id="mycamera" hidden="{{cameraisshow}}" device-position="front">
</camera>
<button class="button-style" bindtap="paizhaoclick">拍照</button>
.wxss
.button-style {
width: 300rpx;
height: 60rpx;
margin-top: 12rpx;
}
.camera-style {
width: 240rpx;
height: 240rpx;
margin-top: 12rpx;
}
.js
var timer; // 计时器
Page({
onReady: function (res) {
this.myCamera = wx.createCameraContext('mycamera')
},
data:{
// text:"这是一个页面"
cameraisshow:false,
srcurl:"",
},
paizhaoclick: function () {
var that = this;
this.myCamera.takePhoto({
quality: 'normal',
success: function (res) {
console.log(res);
var st = res.tempImagePath
console.log(st);
that.setData({ cameraisshow: true, srcurl: st });
},
fail: function (res) {
console.log(res);
}
});
},
})
运行效果:加载图片提示
VM878:2 Failed to load image http://127.0.0.1:63615/tmp/touristappid.o6zAJs_OfeJOCr-DMLPf2dV5xz98.rMRSn5pKtbWS8aaf18d7ce2c3f47f6b2ec57ae40f2df.jpg
net::ERR_EMPTY_RESPONSE ,但是点击路径是可以显示出来的,找不出问题在哪里....