我的这段代码中,所有的括号都被正确地关闭,但我的代码中一直有这样的错误。
这里是语法:(我一直在检查,我发现它们都是正常关闭的,找不到所有这些缺失的小括号背后的原因,而且每当我按照错误指示添加分号时,下一行就会出现同样的错误。
import React from 'react';
import axios from 'axios';
class Form extends React.Component{
constructor(props) {
super(props);
this.state = {
photoData:'',
email: ''
}
}
handle(e){
e.preventDefault();
const{qrUrl}=this.props.qrUrl;
axios.get(`${qrUrl}`)
.then(
(response) => response.json()
).then((data) => {
this.setState({
photoData:data
}).then({
method: "POST",
url:"http://localhost:3002/send",
data: this.state.photoData
}).then((response)=>{
if (response.data.status === 'success'){
alert("Message Sent.");
this.resetForm()
}else if(response.data.status === 'fail'){
alert("Message failed to send.")
}
})
handleSubmit(e){
e.preventDefault();
axios.post({
method: "POST",
url:"http://localhost:3000/send",
data: this.state
}).then((response)=>{
if (response.data.status === 'success'){
alert("Message Sent.");
this.resetForm()
}else if(response.data.status === 'fail'){
alert("Message failed to send.")
}
});
}
render() {
return(
<div className="App">
<form id="contact-form" onSubmit={this.handleSubmit.bind(this)} onClick={this.handle.bind(this)} method="POST">
<div className="form-group">
<label htmlFor="exampleInputEmail1">Email address</label>
<input type="email" className="form-control" id="email" aria-describedby="emailHelp" value={this.state.email} />
</div>
<button type="submit" className="btn btn-primary" >Submit</button>
</form>
</div>
);
}
}
export default Form;
可能是 "handle "函数没有正确关闭,在 "handleSubmit "函数前加两个括号"}}",你的错误可能会得到修正。
你忘了关闭handle函数中的括号------。
handle(e){
e.preventDefault();
const{qrUrl}=this.props.qrUrl;
axios.get(`${qrUrl}`)
.then(
(response) => response.json()
).then((data) => {
this.setState({
photoData:data
}).then({
method: "POST",
url:"http://localhost:3002/send",
data: this.state.photoData
}).then((response)=>{
if (response.data.status === 'success'){
alert("Message Sent.");
this.resetForm()
}else if(response.data.status === 'fail'){
alert("Message failed to send.")
}
})
}) // This one is missing
} // And This one is missing