uni-app 微信小程序前端,Vue 2 语法,家庭教育任务管理。
| Task | Location | Notes |
|---|---|---|
| 页面组件 | pages/*/ |
login, index, tasks, rewards, profile, guide, games等 |
| 页面注册 | pages.json |
TabBar配置和页面路径 |
| 应用配置 | manifest.json |
AppID: wx5ba8038ef16fb245 |
| 全局样式 | uni.scss |
SCSS变量和全局样式 |
| 应用入口 | App.vue |
全局生命周期和配置 |
| 组件库 | components/ |
地址选择器、任务卡片等可复用组件 |
| API配置 | config/ |
baseUrl和请求封装 |
pages/
├── index/ # 首页(角色分流)
├── login/ # 登录页
├── tasks/ # 任务管理
├── rewards/ # 心愿单
├── profile/ # 个人中心
├── guide/ # 成长规划师功能
├── games/ # 小游戏
└── parent/ # 家长专属功能
pages.json 中定义 5 个 TabBar 页面(TabBar 文案,非五维维度名):
pages/index/index - 角色分流入口pages/body/index - 身体健康维度pages/wisdom/index - 智慧维度(心智测评)pages/mind/index - 心理/情感维度pages/profile/profile - 个人设置和积分onLoad、onShowpages.json 中注册uni.navigateTo、uni.redirectTouni.request,统一在 config.baseUrlcomponents/address-picker.vue 四级联动组件pages.json 注册config.baseUrl?.,微信小程序不支持 → 使用 && 代替(如 currentWish?.title 改为 currentWish && currentWish.title):class 绑定中调用方法(如 :class="getStatusClass(item)"),微信小程序模板编译器不支持带参数的方法调用 → 改用内联表达式(如 :class="'status-' + item._cssClass")或计算属性.val-偏高、.badge-低风险),微信小程序 wxss 编译器不支持中文类名 → 使用英文(如 .val-high、.badge-low),数据中的中文状态通过 _cssClass 字段映射pages/match/street-match.vue - 街道地址匹配功能pages/family/address-edit.vue - 家庭地址管理components/address-picker.vue - 省市区街道联动| 包 | 版本 | 原因 |
|---|---|---|
@vue/cli-service |
~4.5.0 |
v5 使用 webpack 5,@dcloudio/uni-mp-weixin 依赖 webpack/lib/GraphHelpers(webpack 4 特有) |
@vue/cli-plugin-babel |
~4.5.0 |
与 cli-service v4 匹配 |
postcss (override + dependency) |
7.0.39 |
remove-scoped.js 在 PostCSS 8 下会走 v8 插件路径,但 spaces 属性访问有兼容问题 |
node-sass |
(devDependency) | @dcloudio/vue-cli-plugin-uni 内置的 sass-loader 需要 |
copy-webpack-plugin |
^5.1.2 |
与 cli-service v4 的 webpack 4 兼容 |
npm install 后会自动运行 postinstall-fix.js,修补 remove-scoped.js 中的 spaces 崩溃:
// 问题: selector.first 可能为 undefined
// 修改前: selector.first.spaces.before = '';
// 修改后: if (selector.first) { selector.first.spaces.before = ''; }
| 错误 | 原因 | 处理 |
|---|---|---|
Cannot read properties of undefined (reading 'spaces') in remove-scoped.js |
PostCSS 节点没有 spaces 属性 |
postinstall-fix.js 自动补丁 |
Cannot find module 'webpack/lib/GraphHelpers' |
@vue/cli-service v5 的 webpack 5 不支持 |
保持 @vue/cli-service ~4.5.0 |
Cannot find module 'node-sass' |
uni-app sass-loader 需要 | npm install node-sass --save-dev |
getPreCompileOptions DevTools 内部错误 |
dist/dev/mp-weixin/ 缺少 project.config.json |
先 npm run build:mp-weixin 生成 dist |
Unexpected token in .vue |
JS 语法错误,常见于方法被截断/拼接错误 | 检查 v-on:click/方法调用是否正确闭合 |
remove-scoped.js 的风险该文件在 node_modules/@dcloudio/vue-cli-plugin-uni/ 内,每次 npm install 会通过 postinstall-fix.js 自动恢复补丁。如需手动执行:
node postinstall-fix.js
不要将 @vue/cli-service 升级到 v5,除非:
@dcloudio/uni-mp-weixin 确认移除了 webpack/lib/GraphHelpers 依赖npm install # 安装依赖(自动运行 postinstall-fix.js)
npm run dev:mp-weixin # 开发模式 (微信小程序)
npm run build:mp-weixin # 构建生产版本(仅生成 dist,不在 DevTools 里编译)
wx5ba8038ef16fb245config/index.js 的 baseUrlnpm run build:mp-weixin 生成 dist/dev/mp-weixin/,然后在 DevTools 中导入该目录