老师您好, store 外部怎么调用?
来源:10-8 【redux-toolkit】sotre配置(configureStore)与异步处理(createAsyncThunk)

慕村5307545
2021-06-15
我自己在外面定义了一个request.js, 里面是axios的自定义拦截,然后检测到后台提示未登录,清空store里面的user信息,user是通过persist存入到localstorege里面的, 所以我想要清空user对象,应该要怎么做;
import store from “…/redux/store”;
let user = store.store.getState().user
// user.id = null;
// user.username = null;
// user.roleId = null;
直接报错
写回答
1回答
-
阿莱克斯刘
2021-06-15
你的拦截器需要放在react组件的生命周期内部,比如说可以与app组件的componentDidMount绑定起来,这样就可以从拦截器访问redux store了。然后通过redux操纵persist来重置localstorage中user的信息了。
022021-06-16
相似问题