北京网帮你
uniapp ifdef编译不同的平台实例
时间:2021-05-09 17:48:25 浏览:123

 uniapp ifdef编译不同的平台实例代码如下。

1、template view下。

<template>
<view>

<!-- #ifdef H5 -->
<view>只在H5编译</view>
<!-- #endif -->

       <!-- #ifdef APP-PLUS -->
<view>只在ios/安卓编译</view>
<!-- #endif -->

       <!-- #ifdef MP -->
<view>只在小程序(微信、支付宝、百度)进行编译</view>
<!-- #endif -->

       <!-- #ifdef MP-WEIXIN -->
<view>只在微信小程序进行编译</view>
<!-- #endif -->


       <!-- #ifndef MP -->
<view>不在小程序全短编译,只在ios/安卓/h5编译</view>
<!-- #endif -->

<view class="color">

</view>

</view>
</template>

2、在js script中

<script>
export default {
data() {
return {

};
},
onLoad() {
// #ifdef H5
console.log("只在H5编译");
// #endif

           // #ifdef APP-PLUS
console.log("只在APP-PLUS编译");
// #endif

           // #ifdef MP
console.log("只在小程序(微信、支付宝、百度)进行编译");
// #endif

           // #ifdef MP-WEIXIN
console.log("只在微信小程序编译");
// #endif
}
}
</script>


3、在css 样式表style中


<style>

.color {
/* #ifdef H5 */
background-color: #008000;
/* #endif */

       /* #ifdef APP-PLUS */
background-color: #FF0000;
/* #endif */

       /* #ifdef MP */
background-color: orange;
/* #endif */

width: 250upx;
height: 250upx;
}

</style>


[上一篇]uniapp js 全局微信浏览器不显示
[下一篇]laravel时间戳转换为日期时时间不
Copyright 2022 © 93580.com.cn 网帮你

2022 © 版权所有 红花岗区网帮你信息技术工作室

工信部备案号:黔ICP备2024036985号-2

请使用网帮你微信扫码登录