使用Element UI的el-upload 上传文件


 

<el-upload
            class="upload_csv"
            ref="upload"
            accept=".csv"
            :action="uploadAPI"
            :multiple="false"
            :limit="1"
            :headers="avatarHeader"
            :on-success="handleSuccess"
            :on-error="handleError"
            :on-progress="hanleProgressing"
          >
            <el-button class="import" size="mini" :loading="isImporting"
              ><i class="el-icon-download"></i>&nbsp;&nbsp;{{
                $t('asset.import')
              }}</el-button
            >
</el-upload>
uploadAPI: process.env.BASE_API + '/importTag',  // 上传的Url地址
computed: {
    avatarHeader() {
      return {
        Authorization: 'bearer ' + getToken()
      }
    }
}
// 上传成功的回调
handleSuccess(response, file, fileList) {
      if (response.success) {
        this.handleResetClear()
        this.getUploadStatus()
        const _this = this
        this.uploadTimer = setInterval(() => {
          _this.getUploadStatus()
        }, 60000)
      }
},


// 上传失败的回调
handleError(response, file, fileList) {
      console.log('error-----------')
      console.log(response)
      this.isImporting = false
      this.$refs.upload.clearFiles()
},

 


免责声明!

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



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