vue3引入router
安装
npm install vue-router@next
创建routers.index.js
import { createRouter, createWebHistory } from 'vue-router';
import Login from '../components/Login.vue';
import Home from '../components/Home.vue';
const router = createRouter({
// 配置你的路由规则
history: createWebHistory(),
routes: [
// 定义你的路由
{
path: '/',
component: Login
},
{
path: '/home',
component: Home
}
]
});
export default router;
main.js引入
import { createApp } from 'vue'
import App from './App.vue'
import router from './routers/index.js'
createApp(App).use(router).mount('#app')
App.vue引入
<template>
<router-view></router-view>
</template>