//压缩照片
compress(fileObj){
// let fileObj = document.getElementById('file').files[0] //上传文件的对象
let _this=this;
let reader = new FileReader()
reader.readAsDataURL(fileObj)
reader.onload = function(e) {
let image = new Image()
image.src = e.target.result
image.onload = function() {
let canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
imageWidth = image.width / 2,
imageHeight = image.height / 2,
data = ''
canvas.width = imageWidth
canvas.height = imageHeight
context.drawImage(image, 0, 0, imageWidth, imageHeight)
data = canvas.toDataURL('image/jpeg')
console.log('压缩后的图片:')
console.log(data)
_this.axios.post('api/multipleUploadFile/doUpload/base64',{
baseContent:data
})
.then(res=>{
console.log('图片上传成功')
console.log(res.data)
_this.imglist.push(res.data.path);
})
}
}
},