/**
* @description 文件下载
* @params {String}result
* @returns {Void}
*/
const result = axios.post('/api/getData', params, { responseType: 'blob' })
export function download (result, name = "download") {
let a = document.createElement('a')
if (typeof result !== 'string') {
a.href = window.URL.createObjectURL(result) // 根据传入的参数创建一个指向该参数对象的URL
} else {
a.href = result
}
a.download = name
a.click()
window.URL.revokeObjectURL(a.href) // 释放一个通过URL.createObjectURL()创建的对象URL
}


/**
* @description 文件下载
* @params {String} url,如:/api/getData?id=1
* @returns {Void}
*/

export function download (url) {
window.open(url, '_blank')
}
展开
评论