一、根据图片链接url 来获取图片宽高
getImageSize(url) {return new Promise((resolve) => {var img = document.createElement("img");img.src = url;img.onload = () => {// 为什么要写 onload 是因为要等他加载完之后才能获取到图片宽高resolve({width:img.naturalWidth,height: img.naturalHeight}); // 2064,4608};});},
二、根据file对象来获取图片宽高
var reader = new FileReader();reader.onload = function (event) {var txt = event.target.result;var img = document.createElement("img");img.src = txt;img.onload = function () {console.log(img.width);console.log(img.height);}};reader.readAsDataURL(file);//使用