Vue3和Vue2的不同及替代方案(TypeScript篇)

发布时间:2023-04-01 18:00

路由篇

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\')

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号