我正在构建一个应用程序在反应本机CRNA,我得到了这个错误后,我要求注册用户的个人资料图片。
对
require
的调用完全期待一个字符串文本参数,但是找到了以下内容:require(this.state.pict)
我有点困惑如何从API调用用户信息项。这是我获取用户数据的代码。
fetch('someurl', {
method: 'GET',
headers:{
Authorization: 'token',
}
})
.then((response)=> response.json())
.then((responseJson)=> {
this.setState({
students: responseJson.data,
loading: false,
})
})
.catch((error)=>{
console.log(error);
});
我将该代码放在componentDidMount()
上,并在图像源中调用this.state.pict
,但得到了前面的错误。谁能告诉我出什么事了吗?我被困住了..。非常感谢。
发布于 2018-10-15 01:17:41
React本机支持两种类型的图像源,本地和网络。
对于需要使用的本地源。例如:
<Image source={require('main/assets/images/your-image.jpg')}/>
对于网络资源,必须使用uri对象。例如:
<Image source={{uri:'https://imgur.com/gallery/Fepmd4K'}/>
请注意,本地映像的源接受使用字符串作为参数传递的请求,而网络映像的源则需要具有uri参数的对象。
您可以在这里阅读更多内容:https://facebook.github.io/react-native/docs/images
关于您的问题,首先尝试console.log
this.state.pic
并查看它的格式,并将其与上面的示例进行匹配,并且应该可以工作。
https://stackoverflow.com/questions/52813118
复制