【问题标题】:React Native fetch Network request failed,only use my APIReact Native 获取网络请求失败,仅使用我的 API
【发布时间】:2017-02-10 23:47:19
【问题描述】:

只有用户我的 API 获取网络请求失败 使用“https://api.douban.com/v2/movie/in_theaters”API就可以了

react-native-cli: 1.0.0 反应原生:0.32.0

fetch('https://api.chooin.com/v1/product/index')
    .then((res) => alert(res))
    .then((data) => {
        // this.setState({
        //     loaded: true,
        //     products: this.state.products.cloneWithRows(data.subjects)
        // });
    })
    .done();

【问题讨论】:

    标签: react-native


    【解决方案1】:

    需要将第一个res解析成json

    fetch('https://api.chooin.com/v1/product/index')
        .then(res => res.json())
        .then(data => {
            return this.setState({
                loaded: true,
                products: this.state.products.cloneWithRows(data.subjects)
            });
        })
        .catch(err => console.log(err));
    

    看这里https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

    【讨论】:

    猜你喜欢
    • 2021-12-06
    • 2021-04-25
    • 2022-09-24
    • 2019-01-06
    • 1970-01-01
    • 2018-06-18
    • 2019-09-09
    • 1970-01-01
    • 2021-04-07
    相关资源
    最近更新 更多