【React Native】那些年RN上跳过的坑

1、github上clone下来的react native 项目,在mac上 react-native run-android 后,报错如下:


Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

按照网上所有的方法,检查了安卓的安装环境,java的安装环境,也没有解决问题,最终在Github上找到了解决方案:
Could not install the app on the device, read the error above for details

 //1.在app的根目录下运行
 chmod 755 android/gradlew
 //2.然后再运行就正常了
 react-native run-android

2、在React Native中使用fetch时,返回的数据如下图:
这里写图片描述

请求代码如下:

     fetch(url)
        .then(response => {
            console.log(response)
        })

结果一直拿不到正常的body对象,而实际应该返回的数据放在了_bodyInit_bodyInit里面,一直找不到原因,后来逛Stack Overflow才发现原因,
这里写图片描述
也就是应该在第一个thenreturn response.json(),然后在下一个then时才能拿到结果。
这里写图片描述

代码如下:

    fetch(url)
        .then(response => {
            return response.json()
        })
        .then(responseData => {
            console.log(responseData)
        })
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值