Commit 2c7c3c63 authored by Administrator's avatar Administrator
Browse files

completed "1.3 阶段性验证1:运行基础项目"

parents
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
max_line_length = 100
* text=auto eol=lf
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"printWidth": 100
}
{
"recommendations": [
"Vue.volar",
"dbaeumer.vscode-eslint",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode"
]
}
# student-app-frontend
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Customize configuration
See [Vite Configuration Reference](https://vite.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```
# Step 0: 整体规划
## 项目概述
student-app-frontend是一个基于Vue 3的前端应用,使用Vite作为构建工具,集成了Vue Router、Pinia状态管理和Vuetify UI框架。项目将实现用户认证、路由控制和响应式界面设计。
## 技术栈
- Vue 3 (Composition API)
- Vite 构建工具
- Vue Router (路由管理)
- Pinia (状态管理)
- Vuetify (UI组件库)
- JavaScript
## 项目结构
```
src/
├── assets/ # 静态资源文件
├── components/ # 公共组件
├── layouts/ # 页面布局组件
├── plugins/ # 插件配置 (如vuetify)
├── router/ # 路由配置
├── stores/ # 状态管理
├── views/ # 页面组件
├── services/ # API服务
└── utils/ # 工具函数
```
## 功能模块
### 1. 路由系统
- 登录页面路由 (`/login`)
- 主页路由 (`/`)
- 个人资料页路由 (`/profile`)
- 路由守卫实现认证控制
### 2. 认证系统
- 用户登录/登出功能
- Token管理 (JWT)
- 认证状态持久化
- 路由守卫集成
### 3. 状态管理
- 使用Pinia管理全局状态
- 认证状态存储
- 用户信息管理
### 4. UI组件
- 使用Vuetify组件库
- 响应式设计
- 统一主题配置
## 开发步骤
1. 项目初始化和环境搭建
2. 集成Vuetify UI框架
3. 配置Vue Router和路由守卫
4. 实现Pinia状态管理
5. 开发认证系统
6. 创建页面组件
7. 集成后端API
8. 样式优化和测试
## 预期成果
- 一个完整的Vue 3前端应用
- 实现用户认证和权限控制
- 响应式UI界面
- 清晰的代码结构和可维护性
\ No newline at end of file
# Step 1: 项目初始化和环境搭建
## 目标
完成Vue 3项目的初始化,安装必要的依赖项,并配置好开发环境。
## 步骤
### 1.1 创建Vue 3 + Vite项目
使用Vue官方的脚手架工具创建新项目:
```bash
npm create vue@latest student-app-frontend
```
在创建过程中选择以下选项:
- 是否使用TypeScript?选择 `No`
- 是否启用JSX支持?选择 `No`
- 是否引入Vue Router进行单页面应用开发?选择 `Yes`
- 是否引入Pinia进行状态管理?选择 `Yes`
- 是否引入Vitest进行单元测试?选择 `No`
- 是否引入Cypress进行端到端测试?选择 `No`
- 是否引入ESLint进行代码质量检查?选择 `Yes`
- 是否引入Prettier进行代码格式化?选择 `Yes`
### 1.2 安装项目依赖
进入项目目录并安装依赖:
```bash
cd student-app-frontend
npm install
```
### 1.3 阶段性验证1:运行基础项目
启动开发服务器:
```bash
npm run dev
```
在浏览器中访问 `http://localhost:5173`,应该能看到Vue的欢迎页面。按 `Ctrl+C` 停止服务器。
### 1.4 安装Vuetify
安装Vuetify和Material Design Icons:
```bash
npm install vuetify @mdi/font
```
### 1.5 配置Vuetify
创建Vuetify插件配置文件 `src/plugins/vuetify.js`
```javascript
import '@mdi/font/css/materialdesignicons.css'
import 'vuetify/styles'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
const vuetify = createVuetify({
components,
directives,
theme: {
defaultTheme: 'light',
themes: {
light: {
colors: {
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FFC107',
},
},
},
},
})
export default vuetify
```
`src/main.js` 中引入并使用Vuetify插件:
```javascript
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
// 引入Vuetify
import vuetify from './plugins/vuetify'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.use(vuetify) // 添加这一行以使用Vuetify
app.mount('#app')
```
### 1.6 阶段性验证2:验证Vuetify集成
修改 `src/App.vue` 文件以测试Vuetify组件:
```vue
<script setup></script>
<template>
<v-app>
<v-main>
<v-container>
<v-row>
<v-col>
<v-card>
<v-card-title>Vue + Vuetify项目初始化成功</v-card-title>
<v-card-text>
<p>这是一个使用Vuetify组件的示例卡片</p>
</v-card-text>
<v-card-actions>
<v-btn color="primary">主要按钮</v-btn>
<v-btn color="secondary">次要按钮</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-container>
</v-main>
</v-app>
</template>
<style scoped></style>
```
再次运行项目:
```bash
npm run dev
```
在浏览器中访问 `http://localhost:5173`,应该能看到一个带有Vuetify样式的卡片组件。这表明Vuetify已经成功集成到项目中。
### 1.7 安装其他依赖(可选)
如果需要额外的工具库,可以安装:
```bash
npm install axios # HTTP客户端
```
## 完成标志
- [x] Vue 3 + Vite项目创建完成
- [x] 依赖安装成功
- [x] 基础项目可以正常运行
- [x] Vuetify成功集成
- [x] Vuetify组件可以正常显示
## 下一步
进入Step 2:配置Vue Router和路由守卫
import { defineConfig, globalIgnores } from 'eslint/config'
import globals from 'globals'
import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
export default defineConfig([
{
name: 'app/files-to-lint',
files: ['**/*.{js,mjs,jsx,vue}'],
},
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
{
languageOptions: {
globals: {
...globals.browser,
},
},
},
js.configs.recommended,
...pluginVue.configs['flat/essential'],
skipFormatting,
])
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}
This diff is collapsed.
{
"name": "student-app-frontend",
"version": "0.0.0",
"private": true,
"type": "module",
"engines": {
"node": "^20.19.0 || >=22.12.0"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint . --fix",
"format": "prettier --write src/"
},
"dependencies": {
"pinia": "^3.0.3",
"vue": "^3.5.18",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@eslint/js": "^9.31.0",
"@vitejs/plugin-vue": "^6.0.1",
"@vue/eslint-config-prettier": "^10.2.0",
"eslint": "^9.31.0",
"eslint-plugin-vue": "~10.3.0",
"globals": "^16.3.0",
"prettier": "3.6.2",
"vite": "^7.0.6",
"vite-plugin-vue-devtools": "^8.0.0"
}
}
<script setup></script>
<template>
<h1>You did it!</h1>
<p>
Visit <a href="https://vuejs.org/" target="_blank" rel="noopener">vuejs.org</a> to read the
documentation
</p>
</template>
<style scoped></style>
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [],
})
export default router
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
})
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment