所以我需要運行此行代碼:訪問狀態從渲染功能
var vehicles = this.state.vehicles;
在渲染功能:
render: function(){...}
目前,我得到這個錯誤:
Uncaught (in promise) TypeError: Cannot read property 'state' of undefined
即使這條線路起作用:
this.setState({vehicles: json})
這也是部分代碼:
getInitialState: function(){
this.render = this.render.bind(this)
return {
vehicles: []
}
}
我怎樣才能解決這個錯誤,並訪問數據?
需要看到你的代碼的一部分,你使用這些語句。它很難猜測 –