uploadPhoto(event){
      var $file = event.currentTarget;
      var file = $file.files;
      let totallen = this.fileList.length+file.length
      if(totallen>4){
        this.$toast('最多上传4张图片!')
          return false
      }
      for (var i = 0; i < file.length; i++) {
        var formData = new FormData()
        // 文件名称,文件对象
        if (file[i].type !== 'image/jpeg' && file[i].type !== 'image/png') {
          this.$toast('只允许上传jpg/png格式的图片!')
          return false
        }
        formData.append("uploadFile", file[i])
        formData.append("tenantId", 'visit')
        formData.append("type",file[i].type.replace('image/',''))
      this.$toast.loading({
        message: "加载中...",
        duration: 0,
        forbidClick: true,
      });
      axios({
          method: 'post',
          url:this.url,
          data:formData,
          headers: {'Content-Type': 'multipart/form-data; boundary=something','token':window.localStorage.getItem('userToken')},
          timeout: 10000
        }).then((res)=>{
          this.$toast.clear();
            if(res.status == 200){
              res.data.forEach(item=>{
                this.fileList.push({
                  localPath: item.path,
                  uploadUrl: item.path,
                  checkinId: this.recId,
                  path: item.path,
                  createTime: new Date(),
                  createUser: this.userName,
                  createUserName: this.realName
                })
              })
            } else {
              this.$toast("上传失败");
            }
          })
          .catch(function (error) {
            this.$toast("上传失败");
          });
      }
    },
 <div
                class="upload-img upload-button"
                v-if="fileList.length<4"
              >
              <input type = "file" accept="image/*" multiple   class='inputbox' @change='uploadPhoto'/>
              </div>

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐