【发布时间】:2017-02-19 07:37:25
【问题描述】:
我正在尝试将数据传递给子组件,但我不断收到未定义的道具。我认为当我在父组件中设置状态时可能有问题。我不应该使用 componentWillMount 吗?
export default class AllItems extends Component {
constructor () {
super()
this.state=({ user: cookie.load('user')})
this.httpHandler = axios.create({
baseURL: 'http://localhost:3000/',
headers: {
'Authorization': this.state.user.token
}
})
}
componentWillMount() {
this.httpHandler('/products/')
.then(function (response) {
this.setState({ winks: response.data.data})
console.log(this.state.winks)
}.bind(this))
}
render() {
return (
<Winks products={this.state.winks} />
)
}
}
【问题讨论】:
标签: reactjs ecmascript-6 components react-jsx