uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['camera'], //這要注意,camera掉拍照,album是打開手機相冊
success(res) {
const tempFilePaths = res.tempFilePaths;
uni.uploadFile({
url: 'https://pro.hxqygl.online/api/carno/status', //服務器地址
fileType: "image", //ZFB必填,不然報錯
filePath: tempFilePaths[0], //這個就是我們上面拍照返回或者先中照片返回的數(shù)組
name: 'img',
success(uploadFileRes) {
let imgData = JSON.parse(uploadFileRes.data)
if(imgData.data == null){
uni.showToast({
title:'查詢失敗',
icon:'error',
duration:2000
})
}else{
uni.showToast({
title: `查詢成功`,
duration: 4000
})
}
_this.chepai = imgData.data.car_no
_this.number = imgData.data.num
// console.log(this);
// this.imgDataUrl = imgData.data.imgUrl
}
});
}
});
需要注意的是我在代碼片段中用到 _this,因為我怕函數(shù)改變了this的指向所有我在方法的開頭就寫了文章來源:http://www.zghlxwxcb.cn/news/detail-718952.html
let _this = this文章來源地址http://www.zghlxwxcb.cn/news/detail-718952.html
到了這里,關于uniapp在微信小程序端調(diào)用攝像頭拍照并且把拍下的圖片上傳到后端的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!