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

郤坚诚
2023-12-01

出现这个错误的原因是请求回来数据时直接跳转,没有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))
}

 

 类似资料:

相关阅读

相关文章

相关问答