beforeUpload(file) { console.log(this.StyleWidth) let isLt2M = true isLt2M = file.size / 1024 / 1024 < this.size if (!isLt2M) { this.loading = false this.$message.error('上传文件过大') } var isSize=this.uploadWidth(file); return isLt2M && isSize }, uploadWidth(file){ //接收父组件传过来的值that.height和that.width var that=this; const isSize = new Promise(function(resolve, reject) { let _URL = window.URL || window.webkitURL; let image = new Image(); image.onload = function() { //控制图片上传大小方法 that.imgWidth=image.width; that.imgHeight=image.height let valid = image.width ==that.width && image.height == that.height; valid ? resolve() : reject(); }; image.src = _URL.createObjectURL(file); }).then( () => { return file; }, () => { this.$message.error("上传头像图片尺寸不符合,只能是"+that.width+"*"+that.height+"!"); return Promise.reject(); } ); return isSize; },
elementUI限制图片上传宽高
最新推荐文章于 2023-12-28 17:22:38 发布