PHP技术论坛

搜索
查看: 686|回复: 0
打印 上一主题 下一主题

Vue 3 路由配置

[复制链接]

83

主题

88

帖子

411

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
411
跳转到指定楼层
楼主
发表于 2022-4-12 10:13:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


1:创建路由文件router.js


2:引入相关模块

  1. import {createRouter,createWebHashHistory} from 'vue-router'
复制代码



3:添加路由配置


  1. export default createRouter({
  2.     history: createWebHashHistory(),
  3.     routes :[{
  4.    
  5.             path: '/user',
  6.             component: User
  7.    
  8.     }]
  9. })
复制代码


也可以把配置文件独立创建

  1. const routers =[
  2.     {
  3.         path: '/',
  4.         component: Main,
  5.         children:[
  6.             {
  7.                 path:'/user/add',
  8.                 component:AddUser
  9.             },{
  10.                 path: '/user/edit',
  11.                 component: EditUser
  12.             }
  13.         ]
  14.     },
  15.     {
  16.         path:'/system/set',
  17.         component:System
  18.     },
  19.     {
  20.         path: '/system/mv',
  21.         component: System
  22.     },
  23.     {
  24.         path:'/user/list',
  25.         component:UserList
  26.     },{
  27.         path: '/user',
  28.         component: User
  29.     }
  30. ]

  31. export default createRouter({
  32.     history: createWebHashHistory(),
  33.     routes :routers
  34. })
复制代码



4:使用模块

  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import router from "@/router"; //引入上面的router.js模块
  4. let vm = createApp(App);
  5. vm.use(router) //使用模块
  6.    vm.mount('#app');
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|PHP  

GMT+8, 2024-5-2 05:00 , Processed in 0.065784 second(s), 36 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表