朋友。我收到了语法错误,指向渲染上方的右大括号。它说它期待逗号,但我不明白为什么。所有花括号都有开括号和右括号。我错过了什么?
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;
答案 0 :(得分:2)
您缺少右括号:
componentWillMount(){
axios.get('my url is in here')
.then((response) => {
this.setState({
sports: response
})
}) // <-- this )
}
}
&#13;
答案 1 :(得分:2)
您需要关闭.then()
,如下所示:
componentWillMount() {
axios.get('my url is in here').then(response => {
this.setState({
sports: response,
});
}); //<--- here, a ) is needed
}
答案 2 :(得分:1)
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 )
}
}