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.


慕妹3146593
浏览 508回答 1
1回答

人到中年有点甜

store.getState() 没有定义 你看看有没有getState这个方法
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript