vue3获取接口返回的图片的宽高

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

注意:一定要onload,要不是异步的,取不到值

封装:

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);
    };
  });
}

调用:

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

版权声明:本文为qq_41697998原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。