下载地址 https://developer.aliyun.com/mirror/npm/package/image-conversion
cnpm安装:
npm i image-conversion --save
调用
import * as imageConversion from 'image-conversion';
例子:以0.9的质量压缩图像
function view(){
const file = document.getElementById('demo').files[0];
console.log(file);
imageConversion.compress(file,0.9).then(res=>{
console.log(res);
})
}
例子:
beforeUpload (file) {
return new Promise((resolve, reject) =>{
if(file.size >= 5594304 ){
this.$refs['upload'].clearFiles();
return this.$message.error("图片不能超过5MB,请重新上传!")
}
imageConversion.compress(file,0.3).then(res=>{
resolve(res);
})
})
},