首页 > Web开发 > 详细

js 页面下载3中方式

时间:2019-09-24 13:15:07      阅读:61      评论:0      收藏:0      [点我收藏+]
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.campusId
this.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)
}

js 页面下载3中方式

原文:https://www.cnblogs.com/bt2882/p/11577632.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!