有一个需求需要把后台返回的头像展示出来;
后台返回接口格式如下:
face_url.jpg
这个时候只需要将从后台返回的数据放在 img 标签的 src 中就可以了
<img src={empoloyeeInfo.faceUrl} alt=""/>
完整代码如下:
- componentDidMount(){
- axios
- .post("/menjin/attendance/select",{uid:'78507b3b83ce455db9a14ac65562ed64'})
- .then((res)=>(
- // console.log(res.data)
- this.setState({
- empoloyeeInfo:res.data.data // 把从后台返回的数据存储在 empoloyeeInfo 中
- })
- )
- }
- render(){
- return(
- <div>
- <img src={this.state.empoloyeeInfo.faceUrl} alt="" />
- </div>
- )
- }
来源: http://www.jianshu.com/p/2e4397c0e2af