音频url如何下载到本地浏览器上
- 一、代码
一、代码
this.downloadFile(url, name)
downloadFile(url, filename) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = function () {
if (xhr.status === 200) {
const blob = new Blob([xhr.response], { type: 'audio/mp3' })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = filename
link.click()
}
}
xhr.send()
},
别看了,没了,就这么简单~