vue-router.esm-bundler.js?6c02:1474 Uncaught TypeError: Cannot read property ‘forEach‘ of undefined
关于vue-cli4.5.13中使用vue-router报错的问题。
以下是报错详情:
vue-router.esm-bundler.js?6c02:1474 Uncaught TypeError: Cannot read property 'forEach' of undefinedat createRouterMatcher (vue-router.esm-bundler.js?6c02:1474)at new createRouter (vue-router.esm-bundler.js?6c02:2777)at eval (index.js?a18c:41)at Module../src/router/index.js (app.js:1482)at __webpack_require__ (app.js:854)at fn (app.js:151)at eval (main.js:12)at Module../src/main.js (app.js:1470)at __webpack_require__ (app.js:854)at fn (app.js:151)
先附上自己的router/index.js代码:
import { createRouter, createWebHistory } from 'vue-router'const Home = ()=>import('views/home/Home')
const Category = ()=>import('views/category/Category')
const Cart = ()=>import('views/cart/Cart')
const Profile = ()=>import('views/profile/Profile')const routers = [{path:'',redirect:'/home'},{path:'/home',component:Home},{path:'/category',component:Category},{path:'/cart',component:Cart},{path:'/profile',component:Profile}
]
const router = new createRouter({history:createWebHistory(),routers
})export default router
百度了好多,发现都无济于事。于是自己寻找了半天发现在定义route数组的时候,把routes写成了routers。又因为在createRouter函数里面使用了简易写法,所以导致在参数里面找不到routes导致的报错。
下面附正确代码:
import { createRouter, createWebHistory } from 'vue-router'// 懒加载
const Home = ()=>import('views/home/Home')
const Category = ()=>import('views/category/Category')
const Cart = ()=>import('views/cart/Cart')
const Profile = ()=>import('views/profile/Profile')// 2.创建router
const routes = [{path:'',redirect:'/home'},{path:'/home',component:Home},{path:'/category',component:Category},{path:'/cart',component:Cart},{path:'/profile',component:Profile}
]const router = new createRouter({history:createWebHistory(),routes
})export default router
希望以后不要犯这种低级错误了
vue-router.esm-bundler.js?6c02:1474 Uncaught TypeError: Cannot read property ‘forEach‘ of undefined相关推荐
- types.js?a742:39 Uncaught TypeError: Cannot read property ‘prototype‘ of undefined at eval (type
vue安装Element第三方组件库浏览器界面报错: types.js?a742:39 Uncaught TypeError: Cannot read property 'prototype' of ...
- Vue错误日记 ——关于Vue-Router出现esm-bundler.js?6c02:2127 Uncaught TypeError: Object(...) is no的解决方案
Vue错误日记 --关于Vue-Router无法正常使用的解决方案 前言 配置 项目环境 项目代码 问题处理 结束语 前言 今天用 Vue-cli 搭建 Vue 项目时,发现Router无法正常挂载, ...
- 接上一篇:【Vue 项目打包后访问报错:Uncaught TypeError: Cannot read property 'call' of undefined】
上一篇:Vue 项目打包后访问报错:Uncaught TypeError: Cannot read property 'call' of undefined 其实在修改 webpack.prod.co ...
- jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined
Jquery DataTable使用报这个错: jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' o ...
- jquery.dataTables.min.js:62 Uncaught TypeError: Cannot read property ‘style‘ of undefined原因
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 报错: jquery.dataTables.min.js:62 Uncaught TypeError ...
- 运行JS代码报错:Uncaught TypeError: Cannot read property‘style‘ of undefined
运行JS代码报错:Uncaught TypeError: Cannot read property'style' of undefined 这个报错的原因通常是没有获取指定的标签: 这个报错的原因通常 ...
- vue-cli3的项目 CDN链接报错解决 Uncaught TypeError: Cannot read property 'prototype' of undefined at Object.
Uncaught ReferenceError: iview is not defined 出现这个问题的原因是路径的问题 确保你的路径是正确的,或者是既全局引入了iview,又按需引入,会造成这样的 ...
- Uncaught TypeError: Cannot read property ‘dispatch‘ of undefined
一.背景描述 用VUE的时候报这个错 Uncaught TypeError: Cannot read property 'dispatch' of undefined 二.问题分析 1.我的代码是酱紫 ...
- Uncaught TypeError: Cannot read property ‘install‘ of undefined
自学vue 刚搭建完项目 配置完路由就不好使了 一直报 Uncaught TypeError: Cannot read property 'install' of undefined 这个错误 //配 ...
最新文章
- 计算机视觉怎样实现自我超越?更大规模更精准的数据
- 听说又有兄弟因为用YYYY-MM-dd 被锤了...
- JQuery 获取自身的HTml代码
- 【机器学习】今天想跟大家聊聊SVM
- 这款堪称完美的PDF编辑器,帮你节省50%的写作时间
- 模块电源(二):电感式DC-DC升压器
- UE4 虚幻引擎,3D数学(一),3D坐标系,2D坐标系
- Hbase 二级索引示意图
- CSR867x — 蓝牙音频发射器方案(支持USB、模拟和SPDIF)
- 微信小程序登录-开发文档
- 谷歌浏览器保存网页为PDF
- 一个老程序员在情人节对中国软件业的致言!(转)
- 《测绘管理与法律法规》真题易错本
- 实例:用C#.NET手把手教你做微信公众号开发(8)--普通消息处理之链接(普通消息终结篇)
- css有哪些动画效果怎么实现的
- 灵魂显示正在登录聊天服务器,Soul跟随灵魂找到你
- v4l2 Camera详细设置
- WindowsForm切换窗口的几种常见实现
- 圆的周长面积(YZOJ-1020)
- 快速入门人工智能的方法及精要