本文最后更新于 2025-04-23T08:16:05+00:00
Vite框架项目创建
1 2 3 4
| npm create vite@latest npm install npm run dev //(别忘记在package.json中"scripts"对象中"dev"后面把"vite"改成"vite --open")
|
Vue Router路由安装
1 2
| npm install vue-router@4 //安装后别忘记在src下新建一个router子文件夹和index.js、routes.js子文件
|
index.js(直接复制粘贴即可)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes.js'
const router = createRouter({ history: createWebHashHistory(), routes: routes, })
router.beforeEach((to, from, next) => { next() })
router.afterEach((to, from) => { })
export default router
|
routes.js(直接复制粘贴即可)
1 2 3 4 5 6 7 8
| const routes = [ { path: '/', name: 'HOME', component: () => import('') } ] export default routes
|
1 2 3
| import router from './router/index.js' createApp(App).use(router).mount('#app')
|
APP.vue初始化
1 2 3 4 5 6 7
| <script setup></script>
<template> <router-view></router-view> </template>
<style scoped></style>
|
style.css初始化
1 2 3 4 5 6 7 8 9 10 11 12
| body { margin: 0; display: flex; place-items: center; }
#app { max-width: 1280px; margin: 0 auto; text-align: center; }
|
Vue.Config
https://taskmanagerol.github.io/Blog/2023/11/13/Vue.Config/