Actions must be plain objects. Use custom middleware for async actions

出现这个错误的原因是请求回来数据时直接跳转,没有dispatch

比如这样会出现错误:

export const getWithdrawCheck = ()  => {
  const userId = getStore('customerUserId', 'session')
  const userPhone = getStore('userPhone', 'session')
  const params = {
    userId,
    userPhone,
    version:'v6',
  }

  get('/activity/luck/check', params).then(({ code, data, message }) => {
    if (code === 0) {
      if (data.can) {
        //注意这里直接跳转了,没有dispatch,所以报错了
        browserHistory.push('/activity/snowball/withdraw')
      } else {
        Toast.info(message)
      }
    } else {
      Toast.fail(message)
    }
  }).catch(message => console.log('getWithdrawCheck', message))
}

所以要dispatch一下:

export const getWithdrawCheck = () => dispatch => {
  const userId = getStore('customerUserId', 'session')
  const userPhone = getStore('userPhone', 'session')
  const params = {
    userId,
    userPhone,
    version:'v6',
  }

  get('/activity/luck/check', params).then(({ code, data, message }) => {
    if (code === 0) {
      if (data.can) {
        // 这里就不会报错了
        dispatch({ type: 'GET_RULER', can: data })
        browserHistory.push('/activity/snowball/withdraw')
        
      } else {
        Toast.info(message)
      }
    } else {
      Toast.fail(message)
    }
  }).catch(message => console.log('getWithdrawCheck', message))
}
发布了115 篇原创文章 · 获赞 38 · 访问量 43万+

猜你喜欢

转载自blog.csdn.net/wangweiscsdn/article/details/85007295