[英]Where is my unexpected token error occurring?
friends. 朋友们。 I'm getting a syntax error, that is pointing at the closing curly bracket just above the render. 我遇到语法错误,它指向渲染上方的右花括号。 It says that it's expecting a comma, but I don't understand why. 它说期望逗号,但是我不明白为什么。 All of the curly brackets have opening and closing brackets. 所有花括号都有开括号和闭括号。 What am I missing? 我想念什么?
import React, {Component} from 'react';
import axios from 'axios';
class List extends Component {
constructor(props){
super(props)
this.state = {
sports: []
}
}
componentWillMount(){
axios.get('my url is in here')
.then((response) => {
this.setState({
sports: response
})
}
}
render(){
return(
<div>
<p>{this.state.sports} </p>
</div>
)
}
}
export default List;
You are missing a right parenthesis: 您缺少右括号:
componentWillMount(){ axios.get('my url is in here') .then((response) => { this.setState({ sports: response }) }) // <-- this ) } }
You need to close the .then()
as follows: 您需要按如下所示关闭.then()
:
componentWillMount() {
axios.get('my url is in here').then(response => {
this.setState({
sports: response,
});
}); //<--- here, a ) is needed
}
import React, {Component} from 'react';
import axios from 'axios';
class List extends Component {
constructor(props){
super(props)
this.state = {
sports: []
}
}
componentWillMount(){
axios.get('my url is in here')
.then((response) => {
this.setState({
sports: response
})
})
}
render(){
return(
<div>
<p>{this.state.sports} </p>
</div>
)
}
}
export default List;
your updated code..
you just miss the closing bracket in componentWillMount() method.
componentWillMount(){
axios.get('my url is in here')
.then((response) => {
this.setState({
sports: response
})enter code here
}) // <-- this )
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.