router/index.js
import { createWebHistory, createRouter } from "vue-router";
import Home from '../views/Home.vue';
import User from '../views/User.vue';
const history = createWebHistory();
const router = createRouter({
history,
routes: [{
path: '/',
component: Home
},
{
path: '/user',
component: User
}
]
})
export default router;
Home.vue
首页
User.vue
user
三.main.js导入router
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
createApp(App).use(router).mount('#app')
四.App.vue添加< router-view> router-view >
在vue3里面使用Router
首页 |
用户
五.访问地址测试跳转
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)