vue 업로드 화면 제한

1605 단어
//    
beforeUpload(file) {
        const isJPG = file.type === 'image/jpeg' || file.type === 'image/gif'
          || file.type === 'image/jpg' || file.type === 'image/png'
          || file.type === 'image/GIF' || file.type === 'image/JPG' || file.type === 'image/bmp';
        // const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isJPG) {
          this.$message.error('       !');
          return false
        }
        //       
        //this.validWidth          props   
       //this.validHeight         props   
        let validWidthAndHeight=true
        if(this.validWidth&&this.validHeight){
          return   this.valWidthAndHeight(file)
        }else return isJPG
      },

 //      
valWidthAndHeight:function(file){
		let _this =this
        return new Promise(function(resolve, reject) {
          let width = _this.validWidth  //    
          let height = _this.validHeight ; //    
          let _URL = window.URL || window.webkitURL;
          let image = new Image();
          image.src = _URL.createObjectURL(file);
          image.onload = function() {
            let valid = image.width == width && image.height == height;
            valid ? resolve() : reject();
          };
        }).then(
          () => {
            return file;
          },
          () => {
            this.$message.error("         ,   "+_this.validWidth+"*"+_this.validHeight+"!");
            return Promise.reject();
          }
        );
      }

좋은 웹페이지 즐겨찾기