当前位置:网站首页>Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
2022-07-06 06:58:00 【王昭没有君啊】
注:这是我工作中搭建项目框架时遇到的一个小问题,分享一下解决方案
1、具体报错:页面一直是白屏,并报以下错误

2、原因分析:
在我仔细思考后,发现是我的 router.beforeEach写在了定义router之前
3、解决方案
只需要将router.beforeEach写在定义router之后,这样就可以解决以上问题。
下面是就是怎样解决报错的代码,顺便附带一份登录权限功能的逻辑。
4、具体代码
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
//引入cookie工具类
import { getToken } from '../utils/cookie'
//设置一份白名单 白名单里的路由不需要登录就能访问
var whiteArr = ['/login','/register','/adminLogin'];
// 登陆权限功能
router.beforeEach((to,from,next) => {
// 当前路由
var path = to.path;
// 获取到token
var token = getToken('token');
if (token) { // 有token说明已经登录
if (path == '/login') { // 如果是登录页
next('/'); // 进入到首页
}
// 如果不是在登录页,发送请求拿到用户基本信息,生成菜单,制作权限 待做!!!
} else { // 没有token说明没有登录
if (whiteArr.includes(path)) { // 当前路由在白名单里
next(); // 放行
} else { // 不在白名单上
next('/login'); // 去登录
}
}
next();
})边栏推荐
- The psychological process from autojs to ice fox intelligent assistance
- Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks
- What is the difference between int (1) and int (10)? Senior developers can't tell!
- 首发织梦百度推送插件全自动收录优化seo收录模块
- 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
- win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
- Chapter 7 - thread pool of shared model
- 19. Actual memory management of segment page combination
- Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
- [brush questions] how can we correctly meet the interview?
猜你喜欢

Apache dolphin scheduler source code analysis (super detailed)

【每日一题】729. 我的日程安排表 I

18. Multi level page table and fast table

Visitor tweets about how you can layout the metauniverse

Pallet management in SAP SD delivery process

After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.

Short video, more and more boring?

AI on the cloud makes earth science research easier

Hydra common commands

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
随机推荐
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
Fast target recognition based on pytorch and fast RCNN
Latex文字加颜色的三种办法
idea控制台彩色日志
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
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
Prefix and array series
Market segmentation of supermarket customers based on purchase behavior data (RFM model)
WPF之MVVM
Every API has its foundation when a building rises from the ground
LeetCode Algorithm 2181. 合并零之间的节点
从autojs到冰狐智能辅助的心里历程
将ue4程序嵌入qt界面显示
PCL realizes frame selection and clipping point cloud
软件测试外包到底要不要去?三年真实外包感受告诉你
Interface automation test framework: pytest+allure+excel
3. Business and load balancing of high architecture
Windows Server 2016 standard installing Oracle
Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
