我正在从Nodejs服务器接收一个bindata,现在我需要显示一个图像。我怎样才能做到这一点?有没有什么方法可以将bindata转换为JPEG或其他格式?或者是否有可能在服务器中转换,然后发送该图像作出反应?如何在React中显示图像?
这是我反应过来的代码片段:
componentDidMount(){
let self = this;
axios.get('http://localhost:8080/list')
.then(function(data) {
console.log(data);
self.setState({post:data.data});
});
}
<ul className="w3-ul w3-card-4 w3-light-grey"> {this.state.post.map((item, index)=> {
return (
<Link to="/displaylist" style={{textDecoration:'none'}} key={index} >
<li className=" w3-hover-green w3-padding-16" onClick={this.handleClick(item.Id)}>
<img src={item.Image.data.data} className="w3-left w3-circle w3-margin-right " width="60px" height="40px" />
<span>{item.Firstname}</span><br/><br/>
</li>
</Link>
)}
)}
</ul>
这是我的NodeJS代码片段:
server.get('/list', function(req, res) {
databaseInterface.listStudent(function(err, students) {
var myJSON = students;
res.json(myJSON);
//You should see the newly saved student here
});
});
你的意思是你的形象就是以base64字符串格式? –
是喜欢系列的人物。 –
你知道如何做到这一点吗? –