缓存问题、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)
      }) 

猜你喜欢

转载自blog.csdn.net/ChasenZh/article/details/108543476