一,代码:
<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:"", } }, onl oad(){ 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
说明:作者:刘宏缔 邮箱: [email protected]
二,测试效果
h5:
小程序:
app:
三,查看hbuilderx的版本:
标签:WEIXIN,18,app,ifdef,js,platform,PLUS,endif,APP From: https://www.cnblogs.com/architectforest/p/17133748.html