关于javascript:下载图片-不预览

28次阅读

共计 397 个字符,预计需要花费 1 分钟才能阅读完成。

down () {

  let request = new XMLHttpRequest()
  request.responseType = 'blob'
  // 传入文件链接
  // request.open('GET', this.tokenData.serverUrl + item.path)
  request.open('GET', 'https://img1.baidu.com/it/u=467403473,3088799256&fm=26&fmt=auto')
  request.onload = function () {let url = window.URL.createObjectURL(this.response)
    let a = document.createElement('a')
    document.body.appendChild(a)
    a.href = url
    a.download = '图片'
    a.click()}
  request.send()

}

正文完
 0