1.npm安装router

npm install vue-router@4

2.创建views和router目录,router中新建index.js

3.index.js中添加内容

import { createRouter, createWebHistory } from 'vue-router'
import page1 from "../views/tubiao2.vue";

const routerHistory = createWebHistory()
const router = createRouter({
    history: routerHistory,
    routes: [
        {
            path: '/',
            name:'Login',
            component: () => import('../views/login.vue')
        },
        {
            path: '/page1 ',
            component: page1 
        },
    ]
})
export default router

4.在main.js中引用

import { createApp } from 'vue'
// import * as echarts from 'echarts'
import router from './router'
import './assets/style.css'
import App from './App.vue'

const app =  createApp(App)
app.use(router)
// app.config.globalProperties.$echarts = echarts
// app.echarts=echarts
app.mount('#app')

完成

Logo

前往低代码交流专区

更多推荐