The download file appears. After the downloaded file is opened, the content is the txt of the download path, and the download does not take effect.

downloadFiles () {
      this.$message.info('文件正在下载,请耐心等待')
      const params = {
        year: this.queryParam.year ? this.queryParam.year : '',
        month: this.queryParam.month ? this.queryParam.month : '',
        week: this.queryParam.week ? this.queryParam.week : ''
      }
      this.axios.get('/spang-safety/sa/download', { params: params, responseType: 'blob' }).then(res => {
        const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
        const url = window.URL.createObjectURL(blob)
        const a = document.createElement('a')
        document.body.appendChild(a)
        a.href = url
        a.download = '效果分析'
        a.click()
        window.URL.revokeObjectURL(url)
      })
    }

Guess you like

Origin blog.csdn.net/weixin_47039061/article/details/131600348