6
對我來說,這個錯誤是相當經常使用axios.can't setstate與未定義property.Eighthough我得到實際的迴應。我很困惑。解決方案將不勝感激。未捕獲(承諾)TypeError:無法讀取undefined屬性'setState'
JSON通過 愛可信回覆回覆
[ { main: 1,
left: 0,
right: 0,
top: 0,
bottom: 0,
cid: 6,
'$created': '2016-10-21T11:08:08.853Z',
'$updated': '2016-10-22T07:02:46.662Z',
stop: 0 } ]
code.js
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
export default class Main extends React.Component{
constructor(props){
super(props);
this.state = {
status:[]
}
}
componentDidMount(){
this.getdata()
}
getdata(){
axios.get('/getactions')
.then(function (data) {
console.log(data.data);
this.setState({
status:data
})
})
}
render(){
console.log(this.state)
return(
<div>
<button >Left</button>
</div>
)
}
}
ReactDOM.render(<Main/>,document.getElementBy
Id('app'))
請張貼的完整堆棧跟蹤異常(應該在dev控制檯中) – Ivan