uniapp-cross-platform
Skill0 starsChanged 18 days agoMITView on GitHub
uni-app 跨端(H5 / 微信小程序 / App)开发与条件编译规范及常见坑。编写 uni-app 页面、组件、pages.json、manifest.json 时使用。
In this repository11 other files it gives its agents.
- pinia-storeSkill
- release-checklistSkill
- uniapp-loginSkill
- uniapp-paymentSkill
- uniapp-performanceSkill
- uniapp-permissionsSkill
- uniapp-project-structureSkill
- uniapp-requestSkill
- uniapp-subpackagesSkill
- uniapp-ui-libsSkill
- vue3-compositionSkill
The file
Files
uni-app 跨端规范
条件编译
<!-- #ifdef MP-WEIXIN -->
<button open-type="getPhoneNumber" @getphonenumber="onPhone">手机号登录</button>
<!-- #endif -->
<!-- #ifdef H5 || APP-PLUS -->
<SmsLogin />
<!-- #endif -->- JS 用
// #ifdef,CSS 用/* #ifdef */;平台标识:H5、MP-WEIXIN、MP-ALIPAY、APP-PLUS(App,Vue3 也可用APP)、MP(所有小程序)。 - 平台差异大时拆文件:
login.mp-weixin.vue不可行,应拆成platform/xxx.ts统一导出,业务层只调统一接口。
必知的坑
- 只用 uni API:
uni.request / uni.setStorageSync / uni.navigateTo,不要用window、document、localStorage、axios(小程序无 XHR)。 - 标签:用
view/text/image,不用div/span/img;纯文本必须包在<text>中,App 端否则可能不显示。 - 单位:用
rpx(750 设计稿 1:1),1px 边框用1px不要用 rpx。 - 样式:小程序不支持
*选择器、标签名选择器受限;组件样式穿透用:deep();page代替body。 - 路由:tabBar 页面只能
uni.switchTab;页面栈最多 10 层,深层跳转用redirectTo;传参需encodeURIComponent(JSON.stringify(obj))。 - 生命周期:页面级用
onLoad/onShow/onReachBottom/onPullDownRefresh(从@dcloudio/uni-app导入),组件里拿不到 onLoad。 - 图片:本地静态图放
static/,小程序包体 2MB 限制,大图走 CDN;image默认 320×240,记得设mode="aspectFill"和宽高。 - 安全区:底部按钮加
padding-bottom: env(safe-area-inset-bottom)。 - H5 跨域:开发期
manifest.json → h5.devServer.proxy或 vite proxy,生产走同域/后端 CORS。 - v-html:小程序用
rich-text,不支持事件和复杂样式。
输出要求
生成代码时注明哪些平台测试过,涉及平台独有能力必须加条件编译和降级方案。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

