首页 > 其他 > 详细

Vue3 Router-基础

时间:2021-06-21 20:45:35      阅读:146      评论:0      收藏:0      [点我收藏+]

1 安装

npm install vue-router@4

 

2 基础使用

定义路由

router.js

import { createRouter,createWebHashHistory} from vue-router 

import About from ../components/About.vue

const routes = [
    { path: /about, component: About },
    //{ path: ‘/home‘, component: Home },
]

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

export default router

注册路由

main.js

import { createApp } from vue
import App from ./App.vue
import router from ./router/index.js


createApp(App).use(router).mount(#app)

使用路由

App.vue 

<template>
    <!-- 创建超链接 可以在不重新加载页面的情况下更改URL-->
    <router-link to="/about">Go to About</router-link>
  <!-- 路由出口 -->
  <!-- 路由匹配到的组件将渲染在这里 -->
  <router-view></router-view>
</template>

 

Vue3 Router-基础

原文:https://www.cnblogs.com/buchizaodian/p/14915273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!