目录
一、实验
1.环境
(1)主机
表1 主机
| 系统 |
软件 | 版本 | 备注 |
| Windows11 | VS Code | 1.96.2 | |
| Node.js | v18.20.4(LTS) |
运行(输入cmd)

查看VS Code版本
Code --version

查看node版本
node -v

查看npm版本
npm -v

2.初始化前端项目
(1)安装vite
cnpm create vite@latest
输入y,然后选择vue
接下来选择JavaScript

(2)安装依赖
切换目录
cd vite-axios
![]()
这里切换cnpm安装依赖
cnpm install

(3) 运行
npm run dev

弹出界面:

可以访问到Vite + Vue
http://localhost:5173/
(4)退出
CTRL + C 结束

输入Y

3.安装 vue-route
(1) 查阅
https://router.vuejs.org/zh/installation.html
(2) 安装vue-router
使用cnpm安装
cnpm install vue-router@4

(3) main.js集成路由
导入router
import router from './router'
注册路由
const app = createApp(App)
app.use(router)
app.mount('#app')
修改前:

修改后:

(4)创建路由配置目录router

(5) router下创建index.js (实现组件与路由映射)

(6)修改index.js
导入创建路由的方法
import { createWebHistory, createRouter } from 'vue-router'
定义路由映射
const listRoutes = {
}
const routes = [
listRoutes,
]
创建路由实例
const router = createRouter({
history: createWebHistory(),
routes,
})
导出默认路由
export default router
(7) 运行
npm run dev

弹出界面:

可以访问到Vite + Vue
http://localhost:5173/
(8)退出
CTRL + C 结束

输入Y

4.安装 pinia
(1) 查阅
https://pinia.vuejs.org/zh/getting-started.html
(2) 安装pinia
使用cnpm安装
cnpm install pinia

(3) main.js集成pinia
导入创建pinia的方法
import { createPinia } from 'pinia'
注册pinia
const pinia = createPinia()
app.use(router).use(pi



最低0.47元/天 解锁文章
10万+

被折叠的 条评论
为什么被折叠?



