<view @tap="ChooseImage">
上传图片
</view>
methods:{
ChooseImage() {
uni.chooseImage({
count: 1, //可选择数量,默认9
sizeType: ['compressed'], //只能上传压缩图
sourceType: ['album','camera'], //从相册选择或从使用相机
success: async (res) => {
if(res.tempFiles[0].size > 10 * 1024 * 1000){ //上传图片大小限制
uni.showToast({
title: "照片大小不能10MB",
icon: "none"
})
return
}
let url = res.tempFilePaths[0];
try{
uni.showLoading({
title:"上传中...",
mask:true
})
let data = await this.$upLoadImg({
apiName:"uploadHouse",
filePath:res.tempFilePaths[0],
name:"file",
})
this.imgUrl = data.data.url;
}catch(e){
console.log(e);
}finally{
uni.hideLoading();
}
}
});
},
}