vant upload圖片上傳 (file文件)


    
<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;

}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM