VUE:router路由使用

1.安装

pnpm add vue-router@4

2.在main.js中导入

import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router' //1导入路由
const app = createApp(App)

app.use(ElementPlus)
app.use(router) //2.应用到app
app.mount('#app') //挂载

3.创建layout路由布局文件 

 

import { createRouter, createWebHistory } from 'vue-router'

//导入组件
import LoginVue from '@/views/Login.vue'
import LayoutVue from '@/views/Layout.vue'


//定义路由关系
const routes = [
    { path: '/login', component: LoginVue },
    {
        path: '/', component: LayoutVue,redirect:'/article/manage', children: [
           //子路由配置区
        {path: 路径 ,component: 导入的子组件名称}
        ]
    }
]

//创建路由器
const router = createRouter({
    history: createWebHistory(),
    routes: routes
})

//导出路由
export default router

 4.在APP.vue中使用路由进行渲染

<script setup>
  
</script>

<template>
  <router-view></router-view> //渲染路由的关键标签
</template>

<style scoped>

</style>

5.成功 

 

 

相关推荐

  1. VueRouter模式有哪几种

    2024-07-18 04:02:05       62 阅读
  2. 使用

    2024-07-18 04:02:05       56 阅读
  3. vue使用

    2024-07-18 04:02:05       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 04:02:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 04:02:05       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 04:02:05       58 阅读
  4. Python语言-面向对象

    2024-07-18 04:02:05       69 阅读

热门阅读

  1. 智能家居的优缺点有哪些?

    2024-07-18 04:02:05       17 阅读
  2. RedisServer解析(一)

    2024-07-18 04:02:05       24 阅读
  3. 【算法模板】数论:杨辉三角求组合数

    2024-07-18 04:02:05       23 阅读
  4. 【算法】位运算

    2024-07-18 04:02:05       21 阅读
  5. day03.04.逻辑运算符

    2024-07-18 04:02:05       18 阅读