vue项目图片上传 vant van-uploader 图片上传


  
vant    van-uploader 图片上传
 
  <van-uploader accept="image/*" v-model="fileList" multiple :after-read="afterRead"></van-uploader>
 
 
 
   
 afterRead: function(file) {
      if (this.fileList.length > 3) {
        this.$toast.fail("图片上传最多三张!");
        this.fileList.splice(3);
        return;
      }
      let formData = new FormData();
      formData.append("file", file.file);
      this.$api.shopOrdersReturnUpload(formData).then(res => {
        if (!res.success) {
          this.$toast.fail("图片上传失败,请重新上传!");
          return;
        }
        if (res.data) {
          this.$toast.success("图片成功!");
          this.fileList[this.fileList.length - 1].r_path = res.data.r_path;
        }
      });
    },
 
重点  axios   
http.interceptors.request.use(
  (config) => {
   config.headers['Content-Type'] = 'multipart/form-data';
  },
  error =>
    Promise.reject(error)
)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM