有什么办法可以导入,这个路由变量在另一个文件中。注意我不想只导入路由变量。下面的代码是我试图做的
src/router.js
const routes = [
{
path:"/",
name:"home",
component: HomeTemplate
},
{
path:"/heroes",
name:"heroes",
component: /*webpackChunkName: Heroes*/ import("@/components/DcHeroes/DcHeroes")
},
{
path:"/calendar",
name:"calendar",
component: /*webpackChunkName: Calendar*/ import("@/components/CalendarTemplate")
},
{
path:"/markdown",
name:"markdown",
component: /*webpackChunkName: Markdown*/ import("@/components/MarkDownTemplate")
},
]
const router = createRouter({
history:createWebHistory(),
routes,
base:'/'
})
export default router;
src/components/navbar/index.vue
<template>
<div>
<h2>Navbar</h2>
<router-link :to="{ name:'home', }">Home</router-link>
<router-link :to="{ name:'heroes', }">Heroes</router-link>
<router-link :to="{ name:'calendar', }">Calendar</router-link>
<router-link :to="{ name:'markdown', }">MarkDown</router-link>
</div>
</template>
<script>
import routes from '@/Router.js'
export default{
name: "NavbarTemplate",
mounted(){
console.log(routes);
}
}
</script>
//import {routes} from '@/Router.js'
// This returns a large object
谢谢。