Created
August 26, 2019 06:24
-
-
Save mcattx/aba71453d9b64757cdcc1a24528b4637 to your computer and use it in GitHub Desktop.
浏览器下载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
download(name, data) { | |
const urlObject = window.URL || window.webkitURL || window; | |
const exportBlob = new Blob([data]); | |
const MIME_TYPE = 'text/plain' | |
const a = document.createElement('a'); | |
a.download = name; | |
a.href = window.URL.createObjectURL(exportBlob); | |
a.textContent = 'Download ready'; | |
a.dataset.downloadurl = [MIME_TYPE, a.download, a.href].join(':'); | |
a.click(); | |
}, | |
// use | |
// data 是后台返回的下载流 | |
// this.download('test.txt', data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment