Document
function change(self){
//上传图片之后的对象数组;(如果后台约定直接通过formData上传,直接上传这里面的对象就好了,可以自行百度)
console.log(self.files);
//创建一个读取文件的对象
let reader = new FileReader();
//读取文件,转码
reader.readAsDataURL(self.files[0]);
reader.onload = function (e) {
let base64 = e.target.result; //转码过后的base64编码
console.log("压缩前", base64.length / 1024);
//创建一个图片
let newImage = new Image();
let quality = 0.6; //压缩系数0-1之间,压缩到0.9以上会有bug,注意!(可以自行设置)
newImage.src = base64;
newImage.setAttribute("crossOrigin", 'Anonymous');//url为外域时需要
let imgWidth, imgHeight;
newImage.onload = function () {
imgWidth = this.width;
imgHeight = this.height;
//给生成图片设置一个默认的宽度(可以自行设置)
let myWidth