一、安装 引入image-conversion
//安装
npm i image-conversion
//页面引入
import { compressAccurately } from "image-conversion";
二、el-upload中 before-upload上传前函数修改
<el-upload
ref="upload"
class="avatar-uploader"
action
multiple
:on-change="handleChange"
:before-upload="beforeUpload"
:http-request="fnUploadRequest"
:on-progress="uploadFileProcess"
:on-success="handleSuccess"
:on-exceed="handleExceed"
:show-file-list="false"
:auto-upload="true"
:limit="maxFile"
:accept="faccept"
:file-list="fileList"
>
</el-upload>
beforeUpload(file) {
let _this = this;
return new Promise(async (resolve, reject) => {
const res = await compressAccurately(file, 500);
file = res;
resolve(file);
});
},