这通常是因为服务器设置了防盗链机制,导致直接从网站上获取图像失败。您可以尝试使用axios获取图像,并在img元素的src属性中使用Blob URL来显示。以下是示例代码:
axios.get(YOUR_IMAGE_URL, { responseType: 'arraybuffer' })
.then(response => {
const blob = new Blob([response.data], { type: 'image/jpeg' });
const imageUrl = URL.createObjectURL(blob);
// 现在可以将imageUrl添加到图像元素中进行显示
})
.catch(error => {
console.log(error);
});
请注意,这只是解决方法之一,具体解决方法可能会因情况而异。
上一篇:Axios请求成功但数据未定义