【问题标题】:Hey stack overflow problem regarding laravel api in expo react嘿,expo react 中有关 laravel api 的堆栈溢出问题
【发布时间】:2020-10-20 08:16:09
【问题描述】:

API 工作正常,但它在警报框帮助中显示未定义的响应,对此非常感谢。登录对象正确返回了状态代码令牌,但是当涉及到警报框时,它总是显示未定义我不知道为什么。我附上了控制台和模拟器的屏幕截图。我想我错过了这个问题,因为 3 天没有在线找到解决方案。

import React , {useState} from 'react';
import {
  StyleSheet,Text,Keyboard,StatusBar
} from 'react-native';
import {Container,Header,Input,Label,Content,Title,Card,CardItem,Button,Body} from 'native-base';

const App: () => React$Node = () => {
  const [email,setEmail] = useState();
  const [password,setPassword] = useState();

  myfun = async()=>{
    //alert(email);
    await fetch('http://172.31.40.233/p.o/api/v1/user/login',{
      method:'POST',
      headers:{
        'Accept': 'application/json',
        //'Content-Type': 'application/x-www-form-urlencoded'
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({"email":email,"password": password})
    }).then(res => res.json())
    .then(resData =>{
      alert(resData.message);
      console.log(resData);
    });
  }
  return (
    <>
      <StatusBar barStyle = "dark-content"/>

      <Container>
        <Content>
          <Header>
            <Title>
              Login
            </Title>
          </Header>
          <CardItem header>
            <Text style ={styles.heading}>Login with Laravel API</Text>
          </CardItem>

          <CardItem>
            <Input placeholder = "Email" style={styles.input}
            value = {email} onChangeText={(value) => setEmail(value)}
            />
          </CardItem>


          <CardItem>
            <Input placeholder = "Password" style={styles.input}
            value = {password} onChangeText={(value) => setPassword(value)}
            />
          </CardItem>


          <CardItem>
            <Body>
            <Button primary block onPress = {myfun}>
              <Text style = {styles.btn}>Login</Text>
            </Button>
            </Body>
          </CardItem>
        </Content>
      </Container>
    </>
  );
};

【问题讨论】:

  • 您提醒resData.message,但这里没有任何内容表明您在响应中收到此字段

标签: laravel api react-native expo


【解决方案1】:

你可以用postman测试你的api,然后在app中使用,这样你就可以分别调试api和app。如果postman没有返回数据,那么在这里粘贴你的laravel函数代码

【讨论】:

    猜你喜欢
    • 2010-10-27
    • 2023-03-05
    • 2010-10-15
    • 1970-01-01
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    相关资源
    最近更新 更多