NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.41k stars 4.78k forks source link

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

Open wgh970312 opened 4 years ago

wgh970312 commented 4 years ago

问题描述

使用redux dispatch 一个Taro.request(),会报Actions must be plain objects. Use custom middleware for async actions.

// login.jsx
this.props.dispatch(login({username: 'username', password: '123456', code: '123456' }))
// user.js //reducer
export function login(data){
  return dispatch => {
    console.log(data)
    // dispatch({type: 'login', payload: true})
    return dispatch(_login(data)).then(res => {
      console.log(res)
    })
  }
}
// api.js
export function login(data) {
  return Taro.request({
    url: `${api}/backend/login/login`,
    method: 'POST',
    data
  }).then(res => {
    return res.data
  })
}

期望行为

可以正常dispatch一个promise

报错信息

image

系统信息

Taro CLI 2.2.1 environment info: System: OS: macOS 10.15.4 Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.16.2 - /usr/local/bin/node Yarn: 1.22.4 - ~/.yarn/bin/yarn npm: 6.14.4 - /usr/local/bin/npm npmPackages: @tarojs/components: 2.2.1 => 2.2.1 @tarojs/components-qa: 2.2.1 => 2.2.1 @tarojs/mini-runner: 2.2.1 => 2.2.1 @tarojs/redux: 2.2.1 => 2.2.1 @tarojs/redux-h5: 2.2.1 => 2.2.1 @tarojs/router: 2.2.1 => 2.2.1 @tarojs/taro: 2.2.1 => 2.2.1 @tarojs/taro-alipay: 2.2.1 => 2.2.1 @tarojs/taro-h5: 2.2.1 => 2.2.1 @tarojs/taro-qq: 2.2.1 => 2.2.1 @tarojs/taro-quickapp: 2.2.1 => 2.2.1 @tarojs/taro-swan: 2.2.1 => 2.2.1 @tarojs/taro-tt: 2.2.1 => 2.2.1 @tarojs/taro-weapp: 2.2.1 => 2.2.1 @tarojs/webpack-runner: 2.2.1 => 2.2.1 eslint-config-taro: 2.2.1 => 2.2.1 eslint-plugin-taro: 2.2.1 => 2.2.1 nerv-devtools: ^1.5.5 => 1.5.6 nervjs: ^1.5.5 => 1.5.6 stylelint-config-taro-rn: 2.2.1 => 2.2.1 stylelint-taro-rn: 2.2.1 => 2.2.1

taro-bot[bot] commented 4 years ago

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~