网络请求失败-Expo React Native

时间:2020-04-10 23:29:24

标签: javascript ios reactjs react-native expo

这真让我讨厌。如果我使用http://my-domain.com,则无法进行网络请求的工作会失败,但是https://my-domain.com会继续为我提供网络请求失败的错误。

我一直在网上寻找,但仍无法解决此问题。请帮忙。

package.json

self.backgroundColor?.setFill()
UIGraphicsGetCurrentContext()!.fill(rect)

},

获取代码

"dependencies": {
"@expo/vector-icons": "~10.0.6",
"@react-native-community/masked-view": "0.1.6",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
"@react-navigation/web": "~1.0.0-alpha.9",
"expo": "~37.0.3",
"expo-asset": "~8.1.3",
"expo-constants": "~9.0.0",
"expo-font": "~8.1.0",
"expo-web-browser": "~8.1.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-iphone-x-helper": "^1.2.1",
"react-native-modalize": "^1.3.7-rc.19",
"react-native-safe-area-context": "0.7.3",
"react-native-screens": "~2.2.0",
"react-native-web": "~0.11.7"

[1]:

Http类

const [contents, setContents] = useState([]);

const fetchChannelContent = (slug) => {
    fetch(Http.api+"/channel/"+slug)
        .then((response) => response.json())
        .then((json) => {
            setContents(json.channel.content);
        })
        .catch((error) => {
            console.error(error);
        });
};

useEffect(() => {
    fetchChannelContent(url)
}, []);[![enter image description here][1]][1]

}

1 个答案:

答案 0 :(得分:0)

export default url {
api: "https://my-domain.com"
}

然后导入该文件和用户url.api