最近做的小程序较多,基本每个小程序都会有意见反馈,所以整理了一下
<view class="picbotm">
<view class="fs34 bold ff col21" style="width: 100%; padding: 40rpx 40rpx;padding-right: 0rpx; box-sizing: border-box;">添加图片</view>
<view class="pics">
<view class="">
<image v-for="(item, index) in upImg"
:src="upImg[index]" :key="index"
mode="" class="pb1"></image>
<image src="../../static/my/addpic@2x.png" mode="" style="width: 200rpx;height: 200rpx;" @click="handleUpload()"></image>
</view>
</view>
</view>
//在methods里面定义方法
handleUpload() {
console.log('上传图片')
uni.chooseImage({
count: 1, // 默认9
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: res => {
uni.showLoading({
title: '加载中',
mask: true
})
uni.uploadFile({
url: 'https://app.qdunwallet.top/QDun-api/api/v1/common/multipleUpload', //仅为示例,非真实的接口地址
filePath: res.tempFilePaths[0],
name: 'files',
success: (res) => {
console.log(JSON.parse(res.data).data,'成功了没');
let data = 'http://fir.qdunwallet.top/'+JSON.parse(res.data).data
console.log(data);
if(this.upImg.length<=8){
console.log(this.upImg.length,'8888' );
this.upImg.push(data)
this.upImg2.push(JSON.parse(res.data).data)
}else{
uni.showToast({
title:'最多上传9张',
icon:'none'
})
return
}
console.log(this.upImg, 'this.upImg');
uni.hideLoading();
}
});
}
});
},