为了账号安全,请及时绑定邮箱和手机立即绑定

redux使用问题

redux使用问题

慕妹3146593 2018-12-20 18:15:21
使用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.
查看完整描述

1 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

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


查看完整回答
反对 回复 2019-01-23
  • 1 回答
  • 0 关注
  • 530 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号