前端uniapp兼容
跨平台适配
使用uni-app的条件编译功能处理不同平台的兼容性问题。语法示例:
// #ifdef H5
console.log('仅在H5平台生效');
// #endif
// #ifdef MP-WEIXIN
console.log('仅在微信小程序生效');
// #endif
API兼容性处理
通过uni.getSystemInfoSync()获取运行环境信息,动态调整API调用方式。例如:
const systemInfo = uni.getSystemInfoSync();
if (systemInfo.platform === 'android') {
// Android特有逻辑
}
CSS样式适配
采用Flex布局结合rpx单位实现响应式设计。使用@media媒体查询针对不同平台调整样式:
/* 通用样式 */
.container {
display: flex;
width: 750rpx;
}
/* H5特有样式 */
@media all and (min-width: 768px) {
.container { padding: 20px; }
}
组件库选择
优先使用uni-ui官方组件库,其内置跨平台兼容逻辑。第三方组件需通过uni_modules导入,并在文档中明确标注支持的平台范围。
真机调试流程
开发阶段通过以下方式验证兼容性:
- 使用
HBuilderX内置模拟器 - 扫码真机调试(iOS/Android)
- 各小程序开发者工具预览
- 最终打包后多设备实测
版本回退策略
在manifest.json中指定最低基础库版本,对低版本用户提供降级方案:
{
"mp-weixin": {
"minPlatformVersion": "1.0.0"
}
}






