當(dāng)前位置:首頁(yè)>文章中心>操作系統(tǒng)>小程序image 網(wǎng)絡(luò)http 協(xié)議不顯示方法(已驗(yàn)證)

小程序image 網(wǎng)絡(luò)http 協(xié)議不顯示方法(已驗(yàn)證)

發(fā)布時(shí)間:2022-10-29 點(diǎn)擊數(shù):6395

 你會(huì)發(fā)現(xiàn)地址正確 但是沒(méi)法顯示。

if (filePath.length < 10) {

filePath = "../../static/logo.png"

}

console.log("地址:" + filePath)

let that = this

const firstCanvas = uni.createCanvasContext('firstCanvas', this);

let scla = 1

uni.getImageInfo({

src: filePath,

success(res) {

that.canvasWidth = res.width * scla

that.canvasHeight = res.height * scla

console.log(res, that.canvasWidth, that.canvasHeight, filePath)

firstCanvas.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);

firstCanvas.draw();

// that.$nextTick(() => { //獲取畫(huà)布像素?cái)?shù)據(jù)


})

},

fail(res) {

console.log("失敗img---:" + res + " url:" + filePath)

}


所以有個(gè)方法  先下載到本地。然后重置一下。

renderFinish() {

if (this.list.id) {

this.$api.shebeiDetail({

id: this.list.id

}).then(res => {

if (res.code == 1) {

this.list.xinghao = res.data.xinghao

const downloadTask = uni.downloadFile({

url: res.data.image, 

success: (res) => {

if (res.statusCode === 200) {

this.list.image = res.tempFilePath;

console.log("本地地址" + this.list.image);

}


}

});


downloadTask.onProgressUpdate((res) => {

console.log('下載進(jìn)度' + res.progress);

console.log('已經(jīng)下載的數(shù)據(jù)長(zhǎng)度' + res.totalBytesWritten);

console.log('預(yù)期需要下載的數(shù)據(jù)總長(zhǎng)度' + res.totalBytesExpectedToWrite);

});



} else {

uni.showToast({

title: ' 錯(cuò)誤:沒(méi)找到這個(gè)設(shè)備 ',

icon: "none"

});

return false;

}

})

}

let filePath = encodeURI(this.list.image)

if (filePath.length < 10) {

filePath = "../../static/logo.png"

}

console.log("地址:" + filePath)

let that = this

const firstCanvas = uni.createCanvasContext('firstCanvas', this);

let scla = 1

uni.getImageInfo({

src: filePath,

success(res) {

that.canvasWidth = res.width * scla

that.canvasHeight = res.height * scla

console.log(res, that.canvasWidth, that.canvasHeight, filePath)

firstCanvas.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);

firstCanvas.draw();

// that.$nextTick(() => { //獲取畫(huà)布像素?cái)?shù)據(jù)


})

},

fail(res) {

console.log("失敗img---:" + res + " url:" + filePath)

}

})


我要評(píng)論

評(píng)論內(nèi)容:

驗(yàn)證碼:
驗(yàn)證碼

滇公網(wǎng)安備 53282302000057號(hào)