1.http图片转file
getImageFileFromUrl(url, imageName, callback) {
// imageName一定要带上后缀
var blob = null
var xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('Accept', 'image/jpeg')
xhr.responseType = 'blob'
xhr.onload = () => {
if (xhr.status == 200) {
blob = xhr.response
let imgFile = new File([blob], imageName, { type: 'image/jpeg' })
callback.call(this, imgFile)
}
}
xhr.send()
}
// 使用
this.getImageFileFromUrl('https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', 'img.jpeg', (file) => {
// this.uploadDate({ raw: file })
})