Skip to content

Redux 中发送异步请求获取数据

步骤

  1. 生命周期函数 componentDidMount(组件被挂载到页面之后,会自动执行)
  2. store.dispatch
  3. reducer return
  4. strore
  5. store.subscribe Update State
componentDidMount () {
    axios.get('http://e.com/api/index/index')
    .then((res) => {
        const data = res.data;
        const action = initListAction(data)
        store.dispatch(action);
    })
    .catch(() => {
        alert('error')
    })
}