# mistake_ui **Repository Path**: actonwong/mistake_ui ## Basic Information - **Project Name**: mistake_ui - **Description**: retfdkljfhsdkljfklerfklperfweedwqfcsdd - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-01 - **Last Updated**: 2024-02-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **🌱 基于 Vue3 全家桶、TypeScript、Vite 构建工具,开箱即用的移动端项目基础模板** - [x] ⚡ Vue3 + Vite4 - [x] 🍕 TypeScript - [x] ✨ Vant4 组件库 - [x] 🍍 Pinia 集成 - [x] Vue-router 4 - [x] 支持 SVG 图标自动注册组件 - [x] vw 视口适配 - [x] Axios 封装 - [x] 打包资源 gzip 压缩 - [x] 开发环境支持 Mock 数据 - [x] ESLint - [x] 首屏加载动画 - [x] 开发环境调试面板 - [ ] TODO: 动态设置页面标题 - [ ] TODO: 生产环境 CDN 依赖 ## 运行项目 注意:要求 Node 版本 16+,可使用 [nvm](https://github.com/nvm-sh/nvm#installing-and-updating) 进行本地 Node 版本管理,同时建议使用 [pnpm](https://pnpm.io/zh/installation) 包管理器。 ```shell # 克隆项目 git clone https://github.com/yulimchen/vue3-h5-template.git # 进入项目目录 cd vue3-h5-template # 安装依赖 pnpm install # 启动服务 pnpm dev ``` 如果你需要的是基于 `vue-cli(webpack)` 或者 `JavaScript` 构建的 H5 项目模板,可切换到 [vue-cli](https://github.com/yulimchen/vue3-h5-template/tree/vue-cli) 分支进行开发 ```shell # 克隆项目 git clone -b vue-cli https://github.com/yulimchen/vue3-h5-template.git # 进入项目目录 cd vue3-h5-template # 安装依赖 yarn # 启动服务 yarn serve ``` ## 文档引导 > - [按需引入 vant 组件](#vant) > - [SVG 图标使用](#svg) > - [路由缓存&命名注意⚠](#router) > - [调试面板 eruda](#console) > - [动态设置页面标题](#page-title) > - [vw视口适配](#viewport) > - [CDN加载依赖](#CDN) ### - 按需引入 vant 组件 全量引入组件库太过臃肿,项目中使用 `unplugin-vue-components` 插件进行按需自动引入组件,可通过[官方文档](https://vant-ui.github.io/vant/#/zh-CN/quickstart#2.-pei-zhi-cha-jian)了解更多。 ### - SVG 图标使用 > 1. 将 svg 图标文件放在 `src/icons/svg` 目录下 > 2. 在项目中直接使用 `` 即可 例如: 本项目 `src/icons/svg` 中放了个叫 `check-in.svg` 的图标文件,然后在组件 `name` 属性中填入文件的命名即可,So easy~ ```Vue ``` > 项目中使用了 `unplugin-vue-components` 自动引入组件,所以 `main.ts` 中无需注册全局图标组件。 ### - 路由缓存&命名注意⚠ 组件默认开启缓存,如某个组件需关闭缓存,在对应路由 `meta` 内的 `noCache` 字段赋值为 `true` 即可。 ```typescript // src/router/routes.ts const routes: Array = [ // ... { path: "about", name: "About", component: () => import("@/views/about/index.vue"), meta: { title: "关于", noCache: true } } ]; ``` 为了保证页面能被正确缓存,请确保**组件**的 `name` 值和对应路由的 `name` 命名完全相同。 ```vue ``` ### - 调试面板 eruda ![](docs/assets/img/Snipaste_2023-02-07_21-57-33.png) 为了方便移动端查看 log 信息和调试,开发环境引入了 eruda 调试面板的 cdn。如果你的开发环境不需要的话请在 `.env.development` 中修改值 ```html # .env.development # 开发环境启用 cdn eruda 调试工具。若不启用,将 true 修改为 false 或其他任意值即可 VITE_ENABLE_ERUDA = "true" ``` ### - 动态设置页面标题(TODO) 在路由全局前置守卫中: ```js // src/router/index.js // ... router.beforeEach((to, from, next) => { // ... // 设置页面 title setPageTitle(to.meta.title) next() }) ``` 具体实现方法见文件 `src/utils/set-page-title.js` 。 ### - 开发环境 Mock > 本项目开发环境支持 mock 请求数据,在 `mock` 目录中可配置接口和数据,具体见[文档](https://github.com/pengzhanbo/vite-plugin-mock-dev-server/blob/main/README.zh-CN.md)。 ### - vw视口适配 使用 `cnjm-postcss-px-to-viewport` 进行视口适配,相关配置见项目根目录下 `postcss.config.js`。 ```js // postcss.config.js module.exports = { plugins: { // 使用 cnjm-postcss-px-to-viewport 规避 postcss.plugin was deprecated 警告 "cnjm-postcss-px-to-viewport": { viewportWidth: 375, // 根据设计稿设定 minPixelValue: 1, // 最小的转换数值 unitPrecision: 2 // 转化精度,转换后保留位数 }, autoprefixer: { overrideBrowserslist: ["Android >= 4.0", "iOS >= 7"] } } }; ``` ### - CDN生产环境依赖(TODO) 本模板生产环境默认 CDN 加载依赖,依赖加载源见根目录 `dependencies-cdn.js` 文件。 **❗ PS.为避免打包后出现不可预估问题,请注意确保生产和开发环境的依赖版本一致!** > 如需关闭 CDN 依赖,在根目录生产环境变量文件 `.env.production` 中修改 `VUE_APP_CDN_DEPS` 的值为 `false` ,重新打包即可。 ## Licenses [MIT license](https://github.com/yulimchen/vue3-h5-template/blob/master/LICENSE).