当前位置:网站首页>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();
})
边栏推荐
- Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
- 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
- Apache dolphin scheduler source code analysis (super detailed)
- 18.多级页表与快表
- Leetcode daily question (1870. minimum speed to arrive on time)
- 巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
- Short video, more and more boring?
- 从autojs到冰狐智能辅助的心里历程
- Day 248/300 thoughts on how graduates find jobs
- 18. Multi level page table and fast table
猜你喜欢
Database basics exercise part 2
C language_ Double create, pre insert, post insert, traverse, delete
19.段页结合的实际内存管理
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
Cif10 actual combat (resnet18)
How to reconstruct the class explosion caused by m*n strategies?
leetcode6109. 知道秘密的人数(中等,周赛)
Top test sharing: if you want to change careers, you must consider these issues clearly!
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
Depth residual network
随机推荐
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
The registration password of day 239/300 is 8~14 alphanumeric and punctuation, and at least 2 checks are included
[daily question] 729 My schedule I
Applied stochastic process 01: basic concepts of stochastic process
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
Redis Foundation
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
UniPro甘特图“初体验”:关注细节背后的多场景探索
19. Actual memory management of segment page combination
【每日一题】729. 我的日程安排表 I
Zhongqing reading news
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
顶测分享:想转行,这些问题一定要考虑清楚!
18.多级页表与快表
Entity Developer数据库应用程序的开发