uni使用new image()報ReferenceError: Image is not defined或者獲取不到對象
JS代碼:
var img = new Image(); // 創建對象 img.src = getBase64List; // 改變圖片的src img.onload = function(e) { // 加載完成執行 contentWidth = this.width, contentHeight = this.height; }
解決方案:
使用用 uni.getImageInfo 代替new image()
uni.getImageInfo({ src: this.getBase64List, success: function (image) { console.log(image); console.log(image.height); var contentWidth = image.width; var contentHeight = image.height; } });