15.uniapp条件编译跨端兼容

<template>
	<view>
		<!-- 方法格式如下注释: 三部曲 -->
		<!--1. #ifdef + 平台值(看文档查看更多)	开头 -->
		<!--2. 内容部分 -->
		<!--3. #endif 	结尾 -->
		
		<!-- #ifdef H5 -->
		<view>我只在H5页面显示</view>
		<!-- #endif -->
		
		<!-- #ifdef MP-WEIXIN -->
		<view>我只在小程序页面显示页面显示</view>
		<!-- #endif -->
		
		<view class="box">s</view>
	</view>
</template>

<script>
	export default{
		methods:{
			// 添加一个方法	加载
			onLoad(){
				// #ifdef H5
				console.log('我只在H5页面打印');
				// #endif
				
				// #ifdef MP-WEIXIN
				console.log('我只在微信小程序里面打印');
				// #endif
				
			}
		}
	}
</script>

<style>
	/* H5页面的样式 */
	// #ifdef H5
	.box{
		width: 100rpx;
		height: 100rpx;
		background-color: #0000FF;
	}
	// #endif
	
	/* 微信小程序中的样式 */
	//	#ifdef MP-WEIXIN
	.box{
		width: 100rpx;
		height: 100rpx;
		background-color: #0000FF;
	}
	// #endif
</style>

おすすめ

転載: blog.csdn.net/m0_49714202/article/details/115678984