Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 为什么输入值没有发送到api_Node.js_React Native_Express_Axios - Fatal编程技术网

Node.js 为什么输入值没有发送到api

Node.js 为什么输入值没有发送到api,node.js,react-native,express,axios,Node.js,React Native,Express,Axios,我需要将值从TextInput传递到API,但我拥有的是下面这个对象,来自控制台。log: Object { "__v": 0, "_id": "5e4422f5c6fc7b323c71db52", } 它是空的。我不知道我做错了什么。我在后端将Node.js与Express和Axios一起使用 import React, { useState } from 'react'; import { View, Text, TextInput, StyleSheet, TouchableOp

我需要将
TextInput
传递到
API
,但我拥有的是下面这个对象,来自
控制台。log

Object {
  "__v": 0,
  "_id": "5e4422f5c6fc7b323c71db52",
}
它是空的。我不知道我做错了什么。我在后端将Node.js与Express和Axios一起使用

import React, { useState } from 'react';
import { View, Text, TextInput, StyleSheet, TouchableOpacity } from 'react-native';

import api from '../services/api';

function CadastroChild({ navigation }){

    const [name, setName] = useState('');
    const [idade, setIdade] = useState('');
    const [peso, setPeso] = useState('');
    const [comprimento, setComprimento] = useState('');
    const [temperatura, setTemperatura] = useState('');

    async function addChild(e){
        e.preventDefault();

        const response = await api.post('/children', {
            name,
            idade,
            peso,
            comprimento,
            temperatura
        })

        console.log(response.data);

    }

    return(
        <View style={styles.container}>
        <View style={styles.childForm}>
            <Text style={styles.textInput}>Nome Completo:</Text>
            <TextInput 
                style={styles.childInput}
                placeholder="Nome da criança"
                placeholderTextColor="#999"
                autoCapitalize="words"
                autoCorrect={false}
                required
                value={name}
                onChange={e => setName(e.target.value)}
            />
            <Text style={styles.textInput}>Idade:</Text>
            <TextInput 
                style={styles.childInput}
                placeholder="Digite a idade"
                placeholderTextColor="#999"
                keyboardType="numeric"
                required
                value={idade}
                onChange={e => setIdade(e.target.value)}
            />
            <Text style={styles.textInput}>Peso (kg):</Text>
            <TextInput 
                style={styles.childInput}
                placeholder="Digite o peso"
                placeholderTextColor="#999"
                keyboardType="numeric"
                required
                value={peso}
                onChange={e => setPeso(e.target.value)}
            />
            <Text style={styles.textInput}>Comprimento (m):</Text>
            <TextInput 
                style={styles.childInput}
                placeholder="Digite o comprimento"
                placeholderTextColor="#999"
                keyboardType="numeric"
                required
                value={comprimento}
                onChange={e => setComprimento(e.target.value)}
            />
            <Text style={styles.textInput}>Temperatura (ºC):</Text>
            <TextInput 
                style={styles.childInput}
                placeholder="Digite a temperatura"
                placeholderTextColor="#999"
                keyboardType="numeric"
                required
                value={temperatura}
                onChange={e => setTemperatura(e.target.value)}
            />
        </View>
        <View style={styles.viewButton}>
            <TouchableOpacity 
                style={styles.goButton}
                onPress={() => { 
                    addChild();
                    navigation.navigate('Menu'); 
                }} 
            ><Text style={styles.textButton}>Cadastrar</Text>
            </TouchableOpacity>
        </View>
        </View>

    );
}

const styles = StyleSheet.create({...})

export default CadastroChild;
import React,{useState}来自“React”;
从“react native”导入{View,Text,TextInput,StyleSheet,TouchableOpacity};
从“../services/api”导入api;
函数CadastroChild({navigation}){
const[name,setName]=useState(“”);
const[idade,setIdade]=使用状态(“”);
const[peso,setPeso]=使用状态(“”);
const[compremento,setcompremento]=useState(“”);
常数[温度,设定温度]=使用状态(“”);
异步函数addChild(e){
e、 预防默认值();
const response=wait api.post(“/children”{
名称
伊达德,
比索,
综合,
温度
})
console.log(response.data);
}
返回(
Nome Completo:
setName(e.target.value)}
/>
Idade:
setIdade(e.target.value)}
/>
比索(千克):
setPeso(e.target.value)}
/>
综合(m):
setCompremento(e.target.value)}
/>
温度(摄氏度):
setTemperatura(e.target.value)}
/>
{ 
addChild();
导航。导航(“菜单”);
}} 
>地籍
);
}
constyles=StyleSheet.create({…})
导出默认的CadastroChild;

我刚刚使用React Native和Node.js。

我想我们需要在
。/services/api
中查看相关代码。我想我们需要在
。/services/api
中查看相关代码