vue3-router使用

 

1.引入router

npm install vue-router@4

 

2.创建文件夹router,并创建index.js文件

import {createRouter,createWebHashHistory} from "vue-router"
const router=createRouter({
    history:createWebHashHistory(),
    routes:[{
        name:'home',
        path:'/',
        component:()=>import('../views/Home.vue')
    }]
});
export default router;

  

3.main.js引入路由

import router from './router/index.js'
let app=createApp(App);
app.use(router).mount('#app');

  

4.App.vue中添加路由组件

<template>
   <router-view></router-view>
</template>

 

以上,仅用于学习和总结

posted @ 2023-02-19 20:00  y_w_k  阅读(33)  评论(0编辑  收藏  举报