后端返回的鏈接放在瀏覽器里直接下載了,要求展示在前端
這個(gè)后端返回的url鏈接(格式是Content-Type:application/octet-stream;charset=UTF-8)不能直接用在img里 需要做一下處理
function fetchImage() {
const url = originUrl //后端返回地址
axios({
method: 'get',
url: url,
responseType: 'blob', // 重要:設(shè)置響應(yīng)類型為blob
})
.then(response => {
// 創(chuàng)建一個(gè)Blob URL
this.imageUrl = URL.createObjectURL(new Blob([response.data]));
})
.catch(error => {
console.error('Fetch error:', error);
});
}