Vue3 gets the width and height of the picture returned by the interface

 let img = new Image();
    img.src = '图片的链接';
    img.onload = async () => {
           console.log(img.width)
           console.log(img.height)
    };`

Note: Be sure to onload, if it is not asynchronous, the value cannot be obtained

Package:

async function getVideo(fileUrl: any) {
    
    
  return new Promise((resolve) => {
    
    
    let img = new Image();
    img.src = fileUrl;
    img.onload = async () => {
    
    
      let type = img.width / img.height > 1 ? "video-w" : "video-h";
      resolve(type);
    };
  });
}

transfer:

    getVideo(url).then((res) => {
    
    
        console.log(res);
        
      });

Guess you like

Origin blog.csdn.net/qq_41697998/article/details/128317495