redux 处理异步请求
方式一:在 componentDidmount 中直接进⾏请求,在将数据同步到 redux
-
创建 Store 仓库
import {
createStore } from 'redux';
const defaultState = {
banners: []
}
const reducer = (state = defaultState, action) => {
switch (action.type) {
case "setBanners":
return {
...state, banners: action.payload