推荐库:
GitHub - fengyuanchen/compressorjs: JavaScript image compressor.
vant 上传压缩示例:
npm i compressorjs -s
import Compressor from 'compressorjs';
before-read 回调中::
beforeRead(file){
let that = this
return new Promise((resolve) => {
// compressorjs 默认开启 checkOrientation 选项
// 会将图片修正为正确方向
new Compressor(file, {
quality: 0.3,
success(result){
// that.fileSize = result.size
resolve(result);
},
error(err) {
console.log(err.message);
},
});
});
},