当前位置:网站首页>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();
})
边栏推荐
- Bio model realizes multi person chat
- Every API has its foundation when a building rises from the ground
- [hot100] 739. Température quotidienne
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- UWA Pipeline 2.2.1 版本更新说明
- Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
- How to find a medical software testing institution? First flight software evaluation is an expert
- 雲上有AI,讓地球科學研究更省力
- Development of entity developer database application
- Apache dolphin scheduler source code analysis (super detailed)
猜你喜欢
万丈高楼平地起,每个API皆根基
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
Cif10 actual combat (resnet18)
Hydra common commands
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
Blue Bridge Cup zero Foundation National Championship - day 20
19. Actual memory management of segment page combination
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
Reflex WMS medium level series 3: display shipped replaceable groups
随机推荐
编译,连接 -- 笔记 -2
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
“无聊猿” BAYC 的内忧与外患
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
leetcode704. 二分查找(查找某个元素,简单,不同写法)
Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
WPF之MVVM
19. Actual memory management of segment page combination
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
Simple query cost estimation
Fedora/rehl installation semanage
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
Redis Foundation
【刷题】怎么样才能正确的迎接面试?
【Hot100】739. 每日温度
Reflex WMS medium level series 3: display shipped replaceable groups
Librosa audio processing tutorial
How to find a medical software testing institution? First flight software evaluation is an expert
Day 246/300 SSH connection prompt "remote host identification has changed!"