redux使用问题

使用react+redux
登录成功后用户信息存在redux中,

用axios封装一个请求http.js,以后每次请求都带自动带上登录成功的token, 如下:
import store from '@/redux/store';
export const get = (obj) => {

let token = store.getState().userRe.token || '';
axios({
  ...obj, 
  method: 'get',
  url: obj.url,
  params: {token},
}).then(() => mull).catch(() => null)

}

我在react-native上这样使用是没问题的,
但是在react中,http.js引入store则会以下错误.

Error: Reducer "userRe" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.

阅读 2.8k
1 个回答

store.getState() 没有定义 你看看有没有getState这个方法

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题