react-native (127.0.0.1) connect service at localhost

访问本地搭建的服务并获取数据:
1、连上手机 adb devices
2、设备端口的设置:(例如:http://127.0.0.1:8000/getUserInfo)
adb reverse tcp:8000 tcp:8000
3、demo

axios
      .get('http://127.0.0.1:8000/getUserInfo')
      .then(res => {
        console.log(res, 'res---获取本地服务器数据');
      })
      .catch(err => {
        console.log(err, 'err---获取本地服务器数据');
      });

注意: 设备不能断开

你可能感兴趣的:(react-native (127.0.0.1) connect service at localhost)