React native React native Config-Setting.env
我正在使用react本机项目中设置环境变量。我的.env配置文件中有一个本地图像url。我可以使用Config.LOGO\u url在我的组件中获取本地图像url。文件的代码段如下所示: 环境配置文件,即.env 我正在组件中使用徽标_URL,如下所示:React native React native Config-Setting.env,react-native,react-redux,react-native-config,React Native,React Redux,React Native Config,我正在使用react本机项目中设置环境变量。我的.env配置文件中有一个本地图像url。我可以使用Config.LOGO\u url在我的组件中获取本地图像url。文件的代码段如下所示: 环境配置文件,即.env 我正在组件中使用徽标_URL,如下所示: import Config from 'react-native-config'; render() { <View> <Image source={require(`../../assets/ima
import Config from 'react-native-config';
render() {
<View>
<Image source={require(`../../assets/images/${Config.LOGO_URL}`)} />
</View>
}
当我试图在图像源中使用配置变量config.LOGO_URL时,我在require中得到错误invalid call。但是,到图像源的硬编码路径正在按预期工作
我错过什么了吗?谢谢提前。问题不在于您在运行时访问图像的配置方式,因为这是一种静态资源,您必须事先需要它,并使用开关之类的东西来更改徽标。 更多信息请参见下面的答案,了解所需图像。
import Config from 'react-native-config';
render() {
<View>
<Image source={require(`../../assets/images/${Config.LOGO_URL}`)} />
</View>
}