使用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()
},

 

posted @ 2020-12-25 10:40  haha-uu  阅读(1488)  评论(0编辑  收藏  举报