文件下载笔记

129 阅读1分钟

下载1(下载的时候不直接打开pdf)

 if (this.isVV(item.file_name) && this.isVV(item.file_path)) {
    fetch(item.file_path).then(res => res.blob()).then(blob => {
        const a = document.createElement('a')
        document.body.appendChild(a)
        a.style.display = 'none'
        // 使用获取到的blob对象创建的url
        const url = window.URL.createObjectURL(blob)
        a.href = url
        // 指定下载的文件名
        a.download = item.file_name
        a.click()
        document.body.removeChild(a)
        // 移除blob对象的url
        window.URL.revokeObjectURL(url)
        })
    }

下载2

window.location.href='xxxx'