文件下载Blob

      request({
        method: 'get',
        url: '/iam-upms-web/upms/func/excel/templates/export',
        // headers: {
        //   token: sessionStorage.getItem('token')
        // },
        responseType: 'blob'
      })
        .then((res) => {
          console.log(res)
          // 文件下载
          const blob = new Blob([res], {
            type: 'application/vnd.ms-excel'
          })
          let link = document.createElement('a')
          link.href = URL.createObjectURL(blob)
          link.setAttribute('download', '功能excel模板.xlsx')
          link.click()
          link = null
          this.$message.success('导出成功')
        })
        .catch((err) => {
          console.log(err)
          this.$message.error('下载失败')
        })
    },

你可能感兴趣的:(javascript,前端,开发语言)