beforeImgUpload (file) {
let promise = this.checkImageSize(file)
promise.then(() => {}, () => {
this.rsForm.image = {}
this.imageObject = []
})
return promise
},
checkImageSize (file) {
var self = this
// eslint-disable-next-line
const isSize = new Promise((resolve, reject) => {
let width = 2048
let height = 2048
let img = new Image()
img.onload = () => {
let vaild = img.width < width && img.height < height
// eslint-disable-next-line
vaild ? resolve() : reject()
}
img.src = window.URL.createObjectURL(file)
}).then(() => {
return file
}, () => {
self.$message({
message: 'Image size cannot be greater than 2048 * 2048',
type: 'warning'
})
// eslint-disable-next-line
return Promise.reject()
})
return isSize
},
beforetlImgUpload (file) {
let promise = this.checkImageSize(file)
promise.then(() => {}, () => {
this.rsForm.timelineShareImage = {}
this.timeImageObject = []
})
return promise
},
beforeSnsImgUpload (file) {
let promise = this.checkImageSize(file)
promise.then(() => {}, () => {
this.rsForm.snsShareImage = {}
this.snsImageObject = []
})
return promise
},
elementui 上传图片前check
最新推荐文章于 2023-12-21 18:31:38 发布