vue3 使用vue-router

这个步骤,我给大家

1,安装 

npm i vue-router@next --save

 

2, main.js 中

import { createApp } from 'vue'
import App from './App.vue'
import {createRouter,createWebHashHistory} from "vue-router"
import rongrong from "./components/rongrong.vue"
import HelloWorld from "./components/HelloWorld.vue"

const VueRouter = createRouter({
    history:createWebHashHistory(),
    routes:[
      {
        path: '/',
        component: HelloWorld
      },
      {
        path: '/rong',
        component: rongrong
      }
    ]
  })
const app = createApp(App);
app.use(VueRouter)
app.mount('#app')

3, App.vue 中,要有路由容器

vue3 使用vue-router_第1张图片

行,测试就没多大问题了

vue3 使用vue-router_第2张图片

你可能感兴趣的:(typescript,composition)