Vue3 第三章 路由使用

1、使用简介如下图

Vue3 第三章 路由使用_第1张图片
vue中引入
Vue3 第三章 路由使用_第2张图片
Vue3 第三章 路由使用_第3张图片

2、安装vue-router

npm install vure-route@4

3、新建路由js文件如下

import {createRouter, createWebHistory} from "vue-router";
import AppMain from "@/components/AppMain.vue";

//定义路由关系
const routes=[
    {path: '/',component:AppMain}
]
//创建路由器
const router= createRouter({
    history:createWebHistory(),
    routes:routes
})
//导出路由
export default router;

4、引入路由

import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from "@/route";

const app = createApp(App)
app.use(ElementPlus)
//引入路由
app.use(router)
app.mount('#app')

5、在App.vue中使用

<script setup>
script>
<template>
<router-view>router-view>
template>
<style scoped>
style>

你可能感兴趣的:(vue)