乐趣区

关于vue.js:Vue3和Vue2的不同及替代方案TypeScript篇

路由篇

router/index.ts 同 ES6 的 router/index.js 写法雷同

import {createRouter, createWebHashHistory} from "vue-router"
import Home from '../views/Home.vue'
const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home
    }
]
const router = createRouter({history: createWebHashHistory(),
    routes
})

export default router

但 main.ts 中不同

import {createApp} from 'vue'
import App from './App.vue'
import router from './router/index' // ES6 中是 import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
const app = createApp(App)

app.use(router).use(ElementPlus).mount('#app')
退出移动版