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>
以上,仅用于学习和总结
标签:vue,import,app,vue3,js,使用,router From: https://www.cnblogs.com/ywkcode/p/17135461.html