antd 上傳圖片獲取寬高


   
    // 尺寸
    getFileWidthAndHeight (file) {
      const _URL = window.URL || window.webkitURL
      const img = new Image()
      img.onload = function () {
        console.log('width , height ', img.width, img.height)
      }
      img.src = _URL.createObjectURL(file)
    }
 
    handleBeforeUpload (file, fileList) {  // 上傳回調
      return new Promise(async (resolve, reject) => {
        this.getFileWidthAndHeight(file)   //看這里
        console.log('handleBeforeUpload...', this.params, file)

        const imageReg = /\.(gif|jpg|jpeg|png|webp|GIF|JPG|JPEG|PNG|WEBP)$/
        if (imageReg.test(file.name)) {
          return this.GetUploadSinature(this.params).then(() => resolve())
        }
        const errText = '請選擇圖片上傳'
        this.$message.error(errText)
        // eslint-disable-next-line prefer-promise-reject-errors
        reject()
      })
    },

// 待補充,實時獲取的file格式

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM