当前位置:网站首页>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();
})
边栏推荐
- Blue Bridge Cup zero Foundation National Championship - day 20
- Fast target recognition based on pytorch and fast RCNN
- leetcode59. 螺旋矩阵 II(中等)
- [daily question] 729 My schedule I
- UDP攻击是什么意思?UDP攻击防范措施
- 这个高颜值的开源第三方网易云音乐播放器你值得拥有
- hydra常用命令
- Leetcode daily question (1870. minimum speed to arrive on time)
- 简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
- 1189. Maximum number of "balloons"
猜你喜欢
Apache DolphinScheduler源码分析(超详细)
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
A brief introduction of reverseme in misc in the world of attack and defense
AI on the cloud makes earth science research easier
1189. Maximum number of "balloons"
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
云上有AI,让地球科学研究更省力
18. Multi level page table and fast table
[brush questions] how can we correctly meet the interview?
Windows Server 2016 standard installing Oracle
随机推荐
librosa音频处理教程
ROS learning_ Basics
3. Business and load balancing of high architecture
Machine learning plant leaf recognition
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品
成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
软件测试外包到底要不要去?三年真实外包感受告诉你
【每日一题】729. 我的日程安排表 I
Monotonic stack
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
【刷题】怎么样才能正确的迎接面试?
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
Pallet management in SAP SD delivery process
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
Kubernetes cluster builds ZABBIX monitoring platform
C语言_双创建、前插,尾插,遍历,删除
18. Multi level page table and fast table
C language_ Double create, pre insert, post insert, traverse, delete
19.段页结合的实际内存管理