2022-06-30

exportHandle() {
      requestfen
        .getProblemInfoExpoerProblemAndUserDemand(this.queryList)
        .then(res => {
          if (!res.code) {
            //通过header中获取返回的文件名称
            let repons = JSON.parse(sessionStorage.getItem('response'))
            let fileName = repons.headers['content-disposition'].split(';')[1].split('filename=')[1]
            let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
            let downloadElement = document.createElement('a')
            var href = window.URL.createObjectURL(blob)
            downloadElement.href = href
            //指定下载的文件的名称,切记进行decode
            downloadElement.download = decodeURI(fileName)
            document.body.appendChild(downloadElement)
            downloadElement.click()
            //移除临时创建对象,释放资源
            document.body.removeChild(downloadElement)
            window.URL.revokeObjectURL(href)
            sessionStorage.removeItem('response')
            this.$message({
              type: 'success',
              message: '文件导出成功!',
            })
          } else {
            this.$message({
              type: 'error',
              message: res.msg,
            })
          }
        })
        .catch(error => {
          this.$message({
            type: 'error',
            message: error.msg,
          })
        })
    },

你可能感兴趣的:(2022-06-30)