Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native React native Config-Setting.env_React Native_React Redux_React Native Config - Fatal编程技术网

React native React native Config-Setting.env

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

我正在使用react本机项目中设置环境变量。我的.env配置文件中有一个本地图像url。我可以使用Config.LOGO\u url在我的组件中获取本地图像url。文件的代码段如下所示:

环境配置文件,即.env

我正在组件中使用徽标_URL,如下所示:

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>
}