html
<van-uploader ref="uploader" v-model="uploader" :before-read="asyncBeforeRead" :preview-image="false" :after-read="afterRead" capture="camera">
</van-uploader>
js
asyncBeforeRead(file) {
console.log('压缩前===========>>>>', file.size) //4M
return this.compressImg(file)
},
afterRead(file) {
console.log('压缩后===========>>>>', file.size) //160k
...略,上传文件到服务端
},
compressImg(file){
return new Promise((resolve, reject) => {
...略,canvas压缩实现
return resolve(file)//返回压缩后的图片
}
}