npm i image-conversion --save
import * as imageConversion from 'image-conversion'
//this.previewSrc需要转换的url
//压缩以后的图片
//imageConversion.compress(data, 0.5) 数字为压缩率1到0.01
this.downloadImageFile(this.previewSrc, function(data) {
imageConversion.compress(data, 0.5).then(res => {
const reader = new FileReader()
reader.readAsDataURL(res)
reader.onload = function(e) {
that.compressSrc = e.target.result
}
})
}),
downloadImageFile(url, callback) {
fetch(url).then(res => {
res.blob().then(myBlob => {
// console.log(myBlob)
callback(blobToFile(myBlob))
})
})
},