gpt4 book ai didi

typescript - 带有 Typescript : missing RouteConfig 的 Vue3 路由器

转载 作者:行者123 更新时间:2023-12-03 06:47:45 29 4
gpt4 key购买 nike

我从 @vue/cli $> vue create my-project 创建了一个新的 vue 项目,激活了 Typescript 选项和路由器选项,并使用 $>vue add vue-next 升级到 vue3 beta .

现在,$>npm run serve失败

ERROR in /home/auser/dev/my-project/src/router/index.ts(1,10):
1:10 Module '"../../node_modules/vue-router/dist/vue-router"' has no exported member 'RouteConfig'.

> 1 | import { RouteConfig, createRouter, createWebHistory } from 'vue-router';
| ^
2 | import Home from '../views/Home.vue'

整个文件没有那么长,后面会用到RouteConfig:

//index.ts
import { RouteConfig, createRouter, createWebHistory } from 'vue-router';
import Home from '../views/Home.vue'

const routes: Array<RouteConfig> = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})

export default router

: RouteConfig 的正确类型是什么,我需要 createRouter ?

最佳答案

你可以这样使用。

import type { RouteRecordRaw } from 'vue-router';

const router = createRouter({
history: createWebHashHistory(),
routes: basicRoutes as RouteRecordRaw[]
});

关于typescript - 带有 Typescript : missing RouteConfig 的 Vue3 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62438045/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com