1、条件编译语句,不同平台在编译出包后已经是不同代码。
<!-- #ifdef MP -->
<!-- 使用组件-->
<search></search>
<!-- #endif -->
2、也可使用uni-app提供的异步(uni.getSystemInfo
)和同步(uni.getSystemInfoSync
)的2个API获取系统信息。(不建议使用,影响性能)
uni.getSystemInfo({
success: (res) => {
switch(res.osName){
case 'ios':
console.log('运行在ios中')
break;
case 'android':
console.log('运行在android中')
break;
default:
console.log('运行在开发者工具中')
}
}
})