首页 > 其他分享 >React+ReactToolKit中,如何在组件外部访问Redux的store,Uncaught ReferenceError: Cannot access slice before initia

React+ReactToolKit中,如何在组件外部访问Redux的store,Uncaught ReferenceError: Cannot access slice before initia

时间:2023-03-03 09:56:44浏览次数:57  
标签:axios slice initialization access Cannot redux store before

之前在项目开发中,遇到一个问题,需要在axios的二次封装文件中,进行拦截,需要使用到redux的dispath派发

但是在axios封装的文件中,直接引入store,出现了如下报错:

Uncaught ReferenceError:  Cannot access "loginslice" before initialization at

解决方案如下:

在axios封装的文件中,创建一个变量,再创建一个函数,函数接收一个参数store,将函数参数接收的store,赋值给变量,抛出函数,在项目的入口文件中,引入刚刚抛出的函数,并调用,传入store,此时,就可以拿到redux的store了

参考链接:

https://redux.js.org/faq/code-structure#how-can-i-use-the-redux-store-in-non-component-files

标签:axios,slice,initialization,access,Cannot,redux,store,before
From: https://www.cnblogs.com/LannyChung/p/17174488.html

相关文章