Vue3-Antd-Admin 项目教程
1. 项目的目录结构及介绍
vue3-antd-admin/
├── public/
│ ├── index.html
│ └── ...
├── src/
│ ├── assets/
│ ├── components/
│ ├── layouts/
│ ├── router/
│ ├── store/
│ ├── views/
│ ├── App.vue
│ ├── main.ts
│ └── ...
├── .gitignore
├── LICENSE
├── README.md
├── package.json
├── tsconfig.json
├── vite.config.ts
└── ...
目录结构介绍
- public/: 存放公共资源文件,如
index.html
。 - src/: 源代码目录。
- assets/: 存放静态资源,如图片、样式文件等。
- components/: 存放可复用的 Vue 组件。
- layouts/: 存放页面布局组件。
- router/: 存放 Vue Router 相关配置。
- store/: 存放 Vuex 状态管理相关配置。
- views/: 存放页面视图组件。
- App.vue: 根组件。
- main.ts: 入口文件。
- .gitignore: Git 忽略配置文件。
- LICENSE: 项目许可证。
- README.md: 项目说明文档。
- package.json: 项目依赖和脚本配置。
- tsconfig.json: TypeScript 配置文件。
- vite.config.ts: Vite 配置文件。
2. 项目的启动文件介绍
main.ts
main.ts
是项目的入口文件,负责初始化 Vue 应用并挂载到 DOM 中。
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
const app = createApp(App);
app.use(router);
app.use(store);
app.mount('#app');
index.html
public/index.html
是项目的入口 HTML 文件,Vite 会将其作为模板生成最终的 HTML 文件。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue3-Antd-Admin</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
3. 项目的配置文件介绍
vite.config.ts
vite.config.ts
是 Vite 的配置文件,用于配置开发服务器、构建选项等。
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
server: {
port: 3000,
},
build: {
outDir: 'dist',
},
});
tsconfig.json
tsconfig.json
是 TypeScript 的配置文件,用于配置 TypeScript 编译选项。
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"]
},
"include": ["src"]
}
package.json
package.json
是项目的依赖和脚本配置文件。
{
"name": "vue3-antd-admin",
"version": "1.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"vue