当前位置:网站首页>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();
})
边栏推荐
- What does UDP attack mean? UDP attack prevention measures
- 19.段页结合的实际内存管理
- 将ue4程序嵌入qt界面显示
- 接口自动化测试实践指导(上):接口自动化需要做哪些准备工作
- 成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
- 18.多级页表与快表
- Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
- WPF之MVVM
- 因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
- [Yu Yue education] flower cultivation reference materials of Weifang Vocational College
猜你喜欢
Kubernetes cluster builds ZABBIX monitoring platform
Fedora/REHL 安装 semanage
漏了监控:Zabbix对Eureka instance状态监控
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
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
Visitor tweets about how you can layout the metauniverse
MPLS experiment
leetcode704. 二分查找(查找某个元素,简单,不同写法)
Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
随机推荐
Hydra common commands
呆错图床系统源码图片CDN加速与破解防盗链功能
ROS2安装及基础知识介绍
简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
微信脑力比拼答题小程序_支持流量主带最新题库文件
Latex文字加颜色的三种办法
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
[Yu Yue education] flower cultivation reference materials of Weifang Vocational College
AI on the cloud makes earth science research easier
Monotonic stack
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
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
leetcode841. 钥匙和房间(中等)
LeetCode Algorithm 2181. 合并零之间的节点
What is the difference between int (1) and int (10)? Senior developers can't tell!
ROS learning_ Basics
A brief introduction of reverseme in misc in the world of attack and defense
UniPro甘特图“初体验”:关注细节背后的多场景探索
Entity Developer数据库应用程序的开发