zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

uni-app:template、js、css中判断平台(hbuilderx 3.6.18)

AppJS平台CSS 判断 18 Template uni
2023-09-14 09:01:15 时间

一,代码:

<template>
    <view style="">
        <view style="margin-top:30rpx; width:710rpx;margin-left: 20rpx; text-align: center;font-size: 50rpx;">
        <!--#ifdef H5-->
        <text class="title">我是h5平台</text>
        <!--#endif-->
        
        <!--#ifdef APP-PLUS-NVUE-->
        <text class="title">我是APP-PLUS-NVUE平台</text>
        <!--#endif-->
        
        <!--#ifdef MP-WEIXIN-->
        <text class="title">我是MP-WEIXIN平台</text>
        <!--#endif-->
        
        <text >js判断当前平台:{{platform}}</text>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                platform:"",
            }
        },
        onLoad(){
            console.log("onLoad:");
            this.getCurrentPlatform();
        },
        methods: {
            getCurrentPlatform(){
               let platform = ""

               //#ifdef APP-PLUS
               platform = 'APP-PLUS'
               //#endif

               //#ifdef APP-PLUS-NVUE
               platform = 'APP-PLUS-NVUE'
               //#endif

               //#ifdef H5
               platform = 'H5'
               //#endif

               //#ifdef MP-WEIXIN
               platform = 'MP-WEIXIN'
               //#endif
               
               console.log(platform);
               this.platform = platform;
               console.log("this.platform:"+this.platform);
            },
        }
    }
</script>

<style>
/* #ifdef H5 */
.title{
    color:#ff0000;
}
/* #endif */
/* #ifdef APP-PLUS-NVUE */
.title{
    color:#ff00ff;
}
/* #endif */
/* #ifdef MP-WEIXIN */
.title{
    color:#0000ff;
}
/* #endif */
</style>

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,测试效果

h5:

 

 小程序:

app:

三,查看hbuilderx的版本: