当前位置:网站首页>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();
})
边栏推荐
- Market segmentation of supermarket customers based on purchase behavior data (RFM model)
- ROS2安装及基础知识介绍
- Chapter 7 - thread pool of shared model
- A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
- ROS学习_基础
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- Zhongqing reading news
- 这个高颜值的开源第三方网易云音乐播放器你值得拥有
- Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
- pymongo获取一列数据
猜你喜欢
基于PyTorch和Fast RCNN快速实现目标识别
A brief introduction of reverseme in misc in the world of attack and defense
RichView TRVStyle 模板样式的设置与使用
Kubernetes cluster builds ZABBIX monitoring platform
Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks
ROS2安装及基础知识介绍
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
Reflex WMS medium level series 3: display shipped replaceable groups
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
随机推荐
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
Entity Developer数据库应用程序的开发
leetcode704. 二分查找(查找某个元素,简单,不同写法)
Prefix and array series
leetcode841. 钥匙和房间(中等)
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
Pallet management in SAP SD delivery process
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
Simple use of JWT
Huawei equipment configuration ospf-bgp linkage
A brief introduction of reverseme in misc in the world of attack and defense
成功解决TypeError: data type ‘category‘ not understood
Missing monitoring: ZABBIX monitors the status of Eureka instance
Day 246/300 SSH connection prompt "remote host identification has changed!"
Three methods of adding color to latex text
Kubernetes cluster builds ZABBIX monitoring platform
《从0到1:CTFer成长之路》书籍配套题目(周更)
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
雲上有AI,讓地球科學研究更省力