如何在React中显示缓冲图像
我是新的react,我有一个端点,将图像返回为缓冲区和文本,但是我有问题将缓冲区转换为img url并显示它,下面是我的代码
<div className={newsStyle.container}>
<ul >
{newsItem.map((news) => {
const Base64string = btoa(
String.fromCharCode(... new Uint8Array(news?.img?.data?.data))
);
<li key={news._id}>
<div className={newsStyle.index}>
<img src={`data: image/png; base64, ${Base64string}`} />
<p className={newsStyle.txt}>{news.title}</p>
</div>
</li>
})}
</ul>
</div>
段地图功能,什么都没有渲染,但是当我删除卷曲时,它会渲染值,但是我无法声明变量
谁能帮忙
i'm new with react and i have an endpoint that returns image as buffer and text, but i'm having issue converting that buffer to img url and displaying it, below is my code snippet
<div className={newsStyle.container}>
<ul >
{newsItem.map((news) => {
const Base64string = btoa(
String.fromCharCode(... new Uint8Array(news?.img?.data?.data))
);
<li key={news._id}>
<div className={newsStyle.index}>
<img src={`data: image/png; base64, ${Base64string}`} />
<p className={newsStyle.txt}>{news.title}</p>
</div>
</li>
})}
</ul>
</div>
now the issue is with the curly bracket in the map function, nothing is rendered, but when i remove the curly it render value, but i wont b able to declare a variable
can anyone help out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您的
地图
没有返回任何内容,因此您可以尝试在地图块中添加返回
Because your
map
does not return anything, you can try add areturn
inside the map block