<div class="upload-img">
<div class="img-box" v-for="(item,index) in uploadImages" :key="index">
<img class="image" :src="item">
</div>
<!-- vant的upload組件 -->
<van-uploader :after-read="onRead" accept="image/*" style="width: 88px;height:88px;">
<img src="../../static/img/evaluate.png" style="width: 100%;height: 100%;">
</van-uploader>
</div>
data() {
uploadImages:[],
};
onRead(file) {
console.log(file);//file文件如下圖
var formData = new FormData(); //構造一個 FormData,把后台需要發送的參數添加
formData.append('file', file.file); //接口需要傳的參數
this.$upload('/single/single/upload', formData).then(res => {//將formDate文件上傳到阿里雲服務器,會返回圖片地址
console.log(res,111111);
let str = res.response_data[0];
this.uploadImages.push(str);//將圖片地址存入一個數組中
});
},
.upload-img{
display: flex;
flex-wrap: wrap;
}
.img-box{
width: 88px;
height: 88px;
margin-right: 8px;
margin-bottom: 8px;
}
.image{
width: 88px;
height: 88px;
}

