小程序image 網(wǎng)絡(luò)http 協(xié)議不顯示方法(已驗(yàn)證)
你會發(fā)現(xiàn)地址正確 但是沒法顯示。
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(() => { //獲取畫布像素數(shù)據(jù)
})
},
fail(res) {
console.log("失敗img---:" + res + " url:" + filePath)
}
所以有個方法 先下載到本地。然后重置一下。
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ù)長度' + res.totalBytesWritten);
console.log('預(yù)期需要下載的數(shù)據(jù)總長度' + res.totalBytesExpectedToWrite);
});
} else {
uni.showToast({
title: ' 錯誤:沒找到這個設(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(() => { //獲取畫布像素數(shù)據(jù)
})
},
fail(res) {
console.log("失敗img---:" + res + " url:" + filePath)
}
})