function changeUpload(e) {
for (let i = 0, j = e.target.files.length; i < j; i ++) {
const file = e.target.files[i]
let reader = new FileReader()
reader.readAsDataURL(file)
let self = this
reader.onload = function() {
compressImg(this.result, file.size, i)
}
}
}
function compressImg(data, size, index) {
let img = new Image()
img.src = data
img.onload = () => {
let width = img.width
let height = img.height
let canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
let ctx = canvas.getContext('2d')
ctx.drawImage(img, 0, 0, width, height)
let ratio = 1
let max = 200 * 1024
if(size > max) ratio = max / size
let key = 'imgData' + index
return canvas.toDataURL("image/jpeg", ratio)
}
}