ユニアプリの条件付きアノテーションは、クロスエンドの互換性を実現します
- 公式ウェブサイト
- #ifdef:定義されている場合は特定のプラットフォームにのみ存在します
- #ifndef:定義されていない場合、特定のプラットフォーム以外に存在します
- %PLATFORM%:プラットフォーム名
ページビューの関連表示
<template>
<view>
<!-- #ifdef H5 -->
<view class="">我希望在h5看见</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="">在小程序看见</view>
<!-- #endif -->
</view>
</template>
- 効果
異なる表示を区別するためのjsコード
- // #ifdef H5 XX // #endif
- // #ifdef MP-WEIXIN XX // #endif
<script>
export default {
onLoad(){
console.log("我只是在H5显示");
console.log("我只是在小程序显示");
}
}
</script>
- 効果
cssの異なるポート表示
<template>
<view>
<!-- #ifdef H5 -->
<view class="">我希望在h5看见</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="">在小程序看见</view>
<!-- #endif -->
</view>
</template>
<script>
export default {
data(){
return {
imgArr:[]
}
},
methods: {
},
}
</script>
<style lang="scss">
view {
color: red;
color: blue;
}
</style>
- 効果