vue项目中爆出这个错误vue-router.esm.js:2316 TypeError: Cannot read properties of undefined (reading '3')
时间: 2023-11-08 20:04:32 浏览: 102
根据您提供的信息,这个错误是由于在创建路由时出现了一些问题导致的。根据引用中的代码,您在创建路由时有一个小错误。在`createRouter`的选项中,应该使用`routes`而不是`routers`作为路由配置项的名称。所以您需要将`routers`改为`routes`,然后重新创建路由实例。修改后的代码如下:
```javascript
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 routes = [
{ path: '', redirect: '/home' },
{ path: '/home', component: Home },
{ path: '/category', component: Category },
{ path: '/cart', component: Cart },
{ path: '/profile', component: Profile }
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router
```
请确保您的代码中没有其他错误,并重新运行您的项目。这个修改应该解决您遇到的错误。
相关推荐
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)