【发布时间】:2018-12-11 11:14:57
【问题描述】:
我是 Redux 的新手。有人可以解释一下,我如何从 Get 获取请求数据
componentDidMount() {
axios.get('/api/v3/products', {
params: {
pageNumber: 1,
pageSize: 500,
}
})
.then(response => {
this.setState({result: response.data});
})
.catch(function (error) {
console.log('error TestMethod', error);
})
.then(function () {
// always executed
});
}
并将其放在 Redux 中的 store 中
const initState = {
products: [
{id: 1, title: 'first'},
{id: 2, title: 'second'},
{id: 3, title: 'third'},
{id: 4, title: 'fourth'},
{id: 5, title: 'fifth'},
],
};
有什么方法吗?
【问题讨论】:
-
我有带有 initState 的 rootReducer,我是否应该将 Get 请求中的代码放在里面?
-
我知道如何将它放在状态中,但是我如何从 Get 中抓取它并将其放置到存储中,这非常困难
标签: javascript reactjs redux get store