当前位置:网站首页>Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
2022-07-06 07:01:00 【Wang Zhao has no king】
notes : This is a small problem I encountered when building the project framework in my work , Share the solution
1、 Specific error report : The page is always blank , And report the following error
2、 Cause analysis :
After I think carefully , The discovery is mine router.beforeEach Written in the definition router Before
3、 Solution
Only need to router.beforeEach Write in definition router after , This can solve the above problems .
The following is how to solve the error reporting code , By the way, a logic of login permission function is attached .
4、 Specific code
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
// introduce cookie Tool class
import { getToken } from '../utils/cookie'
// Set up a white list The routes in the white list can be accessed without login
var whiteArr = ['/login','/register','/adminLogin'];
// Login permission function
router.beforeEach((to,from,next) => {
// Current route
var path = to.path;
// Get token
var token = getToken('token');
if (token) { // Yes token Indicates that you are logged in
if (path == '/login') { // If it's the landing page
next('/'); // Go to the home page
}
// If not on the landing page , Send a request to get basic user information , generate menu , Production permission To be done !!!
} else { // No, token No sign in
if (whiteArr.includes(path)) { // The current route is in the white list
next(); // release
} else { // Not on the white list
next('/login'); // Go to login
}
}
next();
})
边栏推荐
- LeetCode 78:子集
- Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
- 【刷题】怎么样才能正确的迎接面试?
- 一文读懂简单查询代价估算
- Apache dolphin scheduler source code analysis (super detailed)
- 成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
- What is the biggest problem that fresh e-commerce is difficult to do now
- What is the difference between int (1) and int (10)? Senior developers can't tell!
- 18. Multi level page table and fast table
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
猜你喜欢
[daily question] 729 My schedule I
Setting and using richview trvstyle template style
升级版手机检测微信工具小程序源码-支持多种流量主模式
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
微信公众号无限回调授权系统源码 全网首发
Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod
Prefix and array series
Interface automation test framework: pytest+allure+excel
kubernetes集群搭建Zabbix监控平台
Short video, more and more boring?
随机推荐
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
UWA Pipeline 2.2.1 版本更新说明
L'Ia dans les nuages rend la recherche géoscientifique plus facile
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
微信公众号无限回调授权系统源码 全网首发
Machine learning plant leaf recognition
顶测分享:想转行,这些问题一定要考虑清楚!
C language_ Double create, pre insert, post insert, traverse, delete
Apache dolphin scheduler source code analysis (super detailed)
Zhongqing reading news
Simple use of JWT
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
Proteus -- Serial Communication parity flag mode
WPF之MVVM
万丈高楼平地起,每个API皆根基
After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious
UniPro甘特图“初体验”:关注细节背后的多场景探索
pymongo获取一列数据
Kubernetes cluster builds ZABBIX monitoring platform