【发布时间】:2018-03-25 16:42:00
【问题描述】:
import React from 'react';
import { Jumbotron, Button } from 'reactstrap';
import axios from 'axios';
import './App.css'
export default class Form extends React.Component{
constructor(){
super();
this.state={
fname:'',
lname:''
};
}
handleChange = event => {
this.setState({name:event.target.value});;
}
handleSubmit = event =>{
event.preventDefault();
const fname = this.state;
const lname = this.state;
axios.post('http://37692ae9.ngrok.io/api/addDocs',{fname,lname})
.then( res => {
console.log(res);
console.log(res.data);
})
.catch((error) =>{
alert(error);
})
}
render(){
return(
<div>
<div className="container">
<Jumbotron fluid>
<form onSubmit={this.handleSubmit}>
<label>
firstName:
<input type="text" name="fname" onChange={this.handleChange} />
</label>
<label>
lastName:
<input type="text" name="lname" onChange={this.handleChange} />
</label>
<Button type="submit">add</Button>
</form>
</Jumbotron>
</div>
</div>
)
}
}
请帮我使用 axios 在 url 中发布这两个数据 每当我试图发送它不去..
错误是警告:数组或迭代器中的每个子项都应该有一个唯一的“键”属性。
我对 reactjs 很陌生 所以请帮我解决这个问题 并让我的代码执行
【问题讨论】:
-
请发布完整的错误日志
标签: reactjs