想通过在本机反应中使用状态来设置图像 URL [英] wants to set image URL by using state in react native
本文介绍了想通过在本机反应中使用状态来设置图像 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 componentdidmount 生命周期中设置我的状态.
hi i am setting my state in componentdidmount life cycle..but in image url nothing is setting but when i alert it gives my url here is my code where in setting state..
componentDidMount(){
ls.get("savedata").then(data => { this.setState({ name: data.user.name },()=>{alert(this.state.name)}); });
ls.get("savedata").then(data => { this.setState({ image: data.user.profile_photo },()=>alert(this.state.image)); });
}
这里是使用图像组件的视图
here is view where in using image component
<Image source={{uri:this.state.image}}style={{width: 130, height: 110}}
推荐答案
如果您的图像存储在本地,则 Image
标签应如下所示:
If your image is stored locally then the Image
tag should look like this:
<Image
style={styles.stretch}
source={require(this.state.image)}
/>
这篇关于想通过在本机反应中使用状态来设置图像 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文