缓存问题、excel流转化问题

1、nginx配置解决缓存问题

if ($request_filename ~* .*\.(?:htm|html|json)$) {
   add_header Cache-Control "no-store";
}

2、流转化问题 , 注意点:  responseType: 'blob' 或者  responseType: 'arraybuffer' 必须加上,如果有使用Mock模拟数据,会影响导致文件损坏,最好是不要使用mock。(mock重写了原生请求,导致和blob流数据冲突,并且导致promise finally失效

      // window.open(`/cccccc.ajax}`) // 不需要鉴权直接window.open 或者 location.href 
     http.get(`/cccccc.ajax`, {}, {
        responseType: 'blob'
      }).then((response) => {
        let name = new Date().getTime() + '_支付单.xlsx'
        let blob = new Blob([response.data], {type: 'application/vnd.ms-excel'})
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
          window.navigator.msSaveOrOpenBlob(blob, name)
        } else {
          const link = document.createElement('a')
          link.style.display = 'none'
          link.href = URL.createObjectURL(blob)// 创建url对象
          link.download = name
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
          URL.revokeObjectURL(link.href)// 销毁url对象
        }
       }).catch((response) => {
         console.error(response.message)
      }) 

3、下载pdf

function dowanloadpdf() {
    axios({
      method: 'get',
      url:
        'https://v.pdf',
      responseType: 'blob',
    }).then(function (response) {
      const link = document.createElement('a')
      let blob = new Blob([response.data], { type: response.data.type })
      let url = URL.createObjectURL(blob)
      link.href = url
      link.download = '前端工程师必备技能.pdf'
      link.click()
    })
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三木森森の

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值