redux请求api的时候,传参应该在哪个生命周期?
redux请求api的时候,传参应该在哪个生命周期?
//code...
getTopics(tab) {
this.props.dispatch((dispatch, getState) => {
axios.get(`/topics?tab=${tab}&page=1&limit=10`) .then(res => {
dispatch({
type: "Topics_Succ",
data: res.data
});
})
});
}
componentDidMount() {
this.getTopics('good');
this.getTopics('ask');
}
// render...
大家都是怎么用?
componentDidMount componentWillReceiveProps
2 回复
多看看文档… https://reactjs.org/docs/react-component.html#componentdidmount
If you need to load data from a remote endpoint, this is a good place to instantiate the network request.
componentWillReceiveProps 已经被弃用了
componentDidMount