当前位置:网站首页>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 daily question (1870. minimum speed to arrive on time)
- Kubernetes cluster builds ZABBIX monitoring platform
- How to find a medical software testing institution? First flight software evaluation is an expert
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- Three methods of adding color to latex text
- PCL realizes frame selection and clipping point cloud
- Entity Developer数据库应用程序的开发
- Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
- 雲上有AI,讓地球科學研究更省力
- Simple query cost estimation
猜你喜欢
随机推荐
leetcode841. 钥匙和房间(中等)
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
成功解决TypeError: data type ‘category‘ not understood
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
How to reconstruct the class explosion caused by m*n strategies?
How to find a medical software testing institution? First flight software evaluation is an expert
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
Fedora/rehl installation semanage
【刷题】怎么样才能正确的迎接面试?
What does UDP attack mean? UDP attack prevention measures
机器人类专业不同层次院校课程差异性简述-ROS1/ROS2-
Redis Foundation
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
Refer to how customer push e-commerce does content operation
Database basics exercise part 2
The psychological process from autojs to ice fox intelligent assistance
“无聊猿” BAYC 的内忧与外患
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
What is the difference between int (1) and int (10)? Senior developers can't tell!
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5










