js 页面下载3中方式

懵懂的女人 提交于 2019-11-30 09:54:23
1. window.location.href = '请求路径'get方式}2. fetch('请求路径方式拼接上去'get方式).then(res => res.blob().then(blob => {   const a = document.createElement('a')   const url = window.URL.createObjectURL(blob)   const filename = 'aa.xlsx'   a.href = url   a.download = filename   a.click()   window.URL.revokeObjectURL(url) }))3.this.exportData.campusId = this.campusIdthis.exportData.time = this.changeTimes(this.createEndTime)axios({  url:'路径'  method: '方式',  type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',  data: 参数,  responseType: 'blob',  timeout: 120000}).then(response => {  const blob = new Blob([response.data])  const fileName ='aa.xlsx'  if ('download' in document.createElement('a')) { // 非IE下载    const elink = document.createElement('a')    elink.download = fileName    elink.style.display = 'none'    elink.href = URL.createObjectURL(blob)    document.body.appendChild(elink)    elink.click()    URL.revokeObjectURL(elink.href) // 释放URL 对象    document.body.removeChild(elink)  } else { // IE10+下载    navigator.msSaveBlob(blob, fileName)  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!