【发布时间】:2019-02-23 04:57:29
【问题描述】:
我有一个带有一个组件 EventCard 的 js 文件,它包含事件名称、日期、事件图像等。如果事件图像不存在,我想加载一个占位符图像。现在该语句看起来像这样
constructor(props){
super(props);
let imgUrl = props.image ? props.image : require("../assets/images/image.jpg");
this.state = {image: imgUrl}
}
我在渲染中使用 this.state 来获取类似
的源source={{uri: this.state.image}}
在对占位符图像进行 require 时,我奇怪地得到 11,并且 react native 抛出错误说“uri 的值不能从 Double 转换为 String”。
非常感谢您的帮助。
谢谢
【问题讨论】:
标签: javascript reactjs react-native require