1. const getFileObj = async (file)=>{
    2. const reader = new FileReader(); // 创建文件对象
    3. const imgObj = await new Promise((resolve, reject) => {
    4. reader.onload = function (evt) {
    5. const image = new Image();
    6. image.src = evt.target.result;
    7. image.onload = function () {
    8. // 返回图片的宽高
    9. resolve({
    10. width: this.width,
    11. height: this.height
    12. })
    13. }
    14. }
    15. reader.readAsDataURL(file)
    16. })
    17. return imgObj;
    18. }
    19. //上传文件
    20. getFileObj(file).then(res=>{
    21. console.log(res); // 返回 {width, height}
    22. });