下载excel 和 word

下载excel

if (res) {

let url =window.URL.createObjectURL(

new Blob([res], {type:'application/vnd.ms-excel' })

)//处理文档流

  let link =document.createElement('a')

link.style.display ='none'

  link.href =url

  link.download ='本外地车辆'

  document.body.appendChild(link)

link.click()

}else {

message.error('暂无数据,无法导出!')

}

请求接口api封装的axios 重点是要给axios发送请求时加上config参数{responseType:'arraybuffer' }

export function totalitylocalExport({

areaCode,

companyCode,

startDate,

endDate,

}) {

return request.post('/rc/totalitylocal/export', {

areaCode,

companyCode,

startDate,

endDate,

},

{responseType:'arraybuffer' })

}

下载word 同理

if (res) {

let url =window.URL.createObjectURL(

new Blob([res], {type:'application/msword' })

)//处理文档流

  let link =document.createElement('a')

link.style.display ='none'

  link.href =url

  link.download ='非道路检测报告'

  document.body.appendChild(link)

link.click()

}else {

message.error('暂无数据,无法导出!')

}

请求接口api封装的axios 重点是要给axios发送请求时加上config参数{responseType:'blob'}

export function noRoadReportWord({ reportNo }) {

return request.post('/rc/noRoadReport/word',{ reportNo },

{responseType:'blob',}

)

}

你可能感兴趣的:(下载excel 和 word)