5.安装和配置路由 Vue Router
-- 未经授权禁止转载 --

Vue Router 官网

     https://router.vuejs.org/zh

安装
	npm install vue-router@4

src\router\index.js
	import { createRouter, createWebHistory } from "vue-router"

	const routes = [
	    {
	        path: "/login", // http://localhost:5173/login
	        component: () => import("../views/admin/login.vue")
	    }
	]

	const router = createRouter({
	    history: createWebHistory(),
	    routes
	})

	export default router

src\main.js
	import { createApp } from 'vue'
	import App from './App.vue'

	//路由
	import router from './router' //导入路由模块

	const app = createApp(App)
	app.use(router) //将 Vue Router 插件注册到 Vue 应用中
	app.mount('#app')

src\views\admin\login.vue
	<script setup>

	</script>

	<template>
	    登录页
	</template>

	<style scoped>

	</style>

src\App.vue
	<script setup>

	</script>

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

	<style scoped>

	</style>


  • 状态: 已完结
  • 课程价格: 158
  • 课时数量: 52 节课