uniapp获取运行平台

文档:uni.getSystemInfoSync
通过getSystemInfo异步获取系统信息
通过getSystemInfoSync同步获取系统信息
这里返回的uniPlatform表示运行的平台,如果是App运行则返回'app',如果是H5运行则返回'web',如果是微信小程序运行,则返回'微信小程序'
详情如下:

生效条件
app App
web Web
mp-weixin 微信小程序
mp-alipay 支付宝小程序
mp-baidu 百度小程序
mp-toutiao 抖音小程序
mp-lark 飞书小程序
mp-qq QQ小程序
mp-kuaishou 快手小程序
mp-jd 京东小程序
mp-360 360小程序
quickapp-webview 快应用通用(包含联盟、华为)
quickapp-webview-union 快应用联盟
quickapp-webview-huawei 快应用华为

在这里我通过运行平台判断滚动滑块的粘连高度:

getSystem(){
    let data = uni.getSystemInfoSync();
    let stickyHeight = 0;
    if (data.uniPlatform == 'web') {
        stickyHeight = 1250;
    } else if (data.uniPlatform == 'app') {
        stickyHeight = 1300;
    } else {
        stickyHeight = 1250;
    }
}

有些时候还需要区分机型,因为同平台的不同机型渲染会有差异,此时可以用uniPlatform + deviceType + system 等条件组合判断

你可能感兴趣的:(uniapp获取运行平台)