feat: 上传图片 增加尺寸控制

This commit is contained in:
wangjiahao 2021-05-28 10:37:29 +08:00
parent ba3117fbad
commit 81dece8fa5

View File

@ -175,6 +175,10 @@ export default {
const fileResult = res.target.result
const img = new Image()
img.onload = () => {
const scaleWith = img.width / 400
const scaleHeight = img.height / 200
let scale = scaleWith > scaleHeight ? scaleWith : scaleHeight
scale = scale > 1 ? scale : 1
this.$store.commit('addComponent', {
component: {
...commonAttr,
@ -187,8 +191,8 @@ export default {
...commonStyle,
top: 0,
left: 0,
width: img.width,
height: img.height
width: img.width / scale,
height: img.height / scale
}
}
})