账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    redux-thunk action中请求接口,reducer中处理type,return state 视图不更新
    56
    0

    在 action-types.js 中定义

    // 获取提现记录
    export const GETCASHLIST = 'GETCASHLIST'

    在action.js中定义action

    // 获取提现记录列表,保存至redux
    export const getCashList = () => {
      return async dispatch => {
        try{
          const value = await API.getCashList();
          dispatch({
            type: GETCASHLIST,
            value,
            initLoading:false
          })
        }catch(err){
          console.error(err);
        }
      }
    }

    在reducer.js中根据类型返回

    export const cashInfo = (state = defaultState , action = {}) => {
      switch(action.type){
        case GETCASHLIST:
        state.cashList = [...action.value]
        state.initLoading = action.initLoading
        return {...state}
        case ADDTOCASHLIST:
          state.cashList.unshift(action.value);
          return state;
        case RESETUSEMONEY:
          state.usefulMoney = action.value;
          return state;
        default:
          return state;
      }
    }

    上述reducer。js中 case GETCASHLIST: return state 无法更新视图 return {...state} 视图就可以更新
    想问一下是为什么

    具体项目地址:https://github.com/yuanyuansh...

    2
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部