<p class="h90 line-h90 bg-fff text-center ft-32 color-fdb05d bd-bt-eee" @click="photograph(1)">拍照</p>
<p class="h90 line-h90 bg-fff text-center ft-32 color-666" @click="photograph(2)">从手机相册选择</p>
photograph(e){
this.isShowModal = false;
this.cameraTakePicture(e)
},
cameraTakePicture(mySourceType) {
navigator.camera.getPicture(this.onSuccess, this.onFail, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
encodingType: Camera.EncodingType.JPEG,
sourceType: mySourceType,
})
},
// 第四步
onSuccess(e){
var that = this
console.log(e)
that.avatar = 'data:image/jpeg;base64,'+e;
//that.test1 = that.avatar
var param = new FormData();
param.append("avatar", that.avatar);
let config = {
headers: {'Content-Type': 'multipart/form-data'}
}
that.$apily.addimage(param,config)
.then(res =>{
//that.test2 = res
console.log(res)
that.avatar = res.data
//that.test3 = that.avatar
})
},
onFail(error){
console.log(error)
},
原生相机/相册上传图片
猜你喜欢
转载自blog.csdn.net/weixin_43888129/article/details/89491417
今日推荐
周排行