vue + elementUI——upload傳數據給后台出錯后再次點擊upload無效


解決方法:使用upload.clearFiles()方法清空文件列表

頁面:

 <el-upload
   ref="upload_file"
    action=""
    :multiple="false"
    :limit="1"
    :show-file-list="false"
    :on-change="importExcel"
    :auto-upload="false">
      <el-button
          :loading="btnLoading"
            type="primary">
            本地上傳
        </el-button>
</el-upload>

js:

importExcel(response) {
        let _this = this;
        _this.$refs.upload_file.clearFiles();
        let fileType = response.name.substring(response.name.lastIndexOf('.') + 1);
        if ((fileType == 'xlsx') || (fileType == 'xls')) {
        //后續處理是我的情況,按照個人需求修改即可
          let ossData = new FormData();
          ossData.append('file', response.raw);
          ossData.append('type', 1);

          _this.$http.post('***', ossData, {
            headers: {
              'Content-Type': 'multipart/form-data',
              'token': localStorage.getItem('token')
            }
          }).then((res) => {
            if (res.status == 200 && res.data.code == 1) {
              _this.$message({
                message: '導入成功!',
                type: 'success'
              });
            } else {
              _this.$message.error('導入失敗!');
            }
          }).catch((err) => {
              _this.$message.error('導入失敗!');
            }
          )
        } else {
          _this.$message.error('文件格式錯誤,請重新選擇!');
        }
},    

 


免責聲明!

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



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