# uni-app-x 项目模板 ## 官方文档 参考官方文档:https://uniapp.dcloud.net.cn/quickstart-cli.html ## 标准项目结构 ``` my-uniappx-project/ ├── src/ │ ├── pages/ # 页面目录 │ │ ├── index/ │ │ │ └── index.vue │ │ └── ... │ ├── components/ # 组件目录 │ │ └── ... │ ├── static/ # 静态资源 │ ├── utils/ # 工具函数 │ ├── api/ # API 接口 │ ├── store/ # 状态管理(Pinia) │ ├── App.vue # 应用入口 │ └── main.ts # TypeScript 入口 ├── manifest.json # 应用配置 ├── pages.json # 页面路由配置 ├── vite.config.ts # Vite 配置 ├── tsconfig.json # TypeScript 配置 └── package.json ``` ## manifest.json 模板 ```json { "name": "my-uniappx", "appid": "", "description": "uni-app-x 项目", "versionName": "1.0.0", "versionCode": "100", "transformPx": false, "uni-app-x": { "compilerVersion": "1.0.0", "vueVersion": "3", "typescript": true }, "app-plus": { "usingComponents": true, "compilerVersion": 3 }, "h5": { "router": { "mode": "hash", "base": "/" } }, "mp-weixin": { "appid": "", "setting": { "urlCheck": false }, "usingComponents": true } } ``` ## pages.json 模板 ```json { "pages": [ { "path": "pages/index/index", "style": { "navigationBarTitleText": "首页" } } ], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app-x", "navigationBarBackgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8" } } ``` ## 页面模板(TypeScript + Composition API) ```vue ``` ## 组件模板(TypeScript) ```vue ``` ## App.vue 模板 ```vue ``` ## main.ts 模板 ```typescript import { createSSRApp } from 'vue' import App from './App.vue' export function createApp() { const app = createSSRApp(App) return { app } } ``` ## vite.config.ts 模板 ```typescript import { defineConfig } from 'vite' import uni from '@dcloudio/vite-plugin-uni' export default defineConfig({ plugins: [uni()], server: { port: 3000, open: true } }) ``` ## tsconfig.json 模板 ```json { "compilerOptions": { "target": "ES2020", "module": "ESNext", "lib": ["ES2020", "DOM"], "jsx": "preserve", "moduleResolution": "node", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "isolatedModules": true, "types": ["@dcloudio/types"] }, "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"], "exclude": ["node_modules"] } ```