今天碰到一個(gè)接口,后端返的二維碼是文件流,在preview里能看到,但response里啥都沒有,這種情況怎么拿到這張圖片呢?
第一步:設(shè)置請(qǐng)求
文章來源:http://www.zghlxwxcb.cn/news/detail-523223.html
//axios封裝的請(qǐng)求里面的responseType要設(shè)置為blob
第二步:頁面調(diào)用接口,使用接口返回回顯圖片
文章來源地址http://www.zghlxwxcb.cn/news/detail-523223.html
<img :src="bigPoster" alt="" class="bigPoster" /> //頁面圖片元素
async myInviteCode() {
var data = {};
try {
let res = await this.$http("myInviteCode", data, "post", true, true);
console.log(res);//打印能看到文件流
const href = window.URL.createObjectURL(res.data);//轉(zhuǎn)成url格式
this.bigPoster = href; //賦值
} catch (error) {
console.log(error);
}
},
到了這里,關(guān)于VUE項(xiàng)目后端接口返回圖片流,圖片在preview里,怎么把圖片顯示到頁面上?的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!