跨端兼容,条件编译;#ifedf与#endif

// #ifedf H5// #endif 必须成对出现
注意注释方式不同

template中

<!-- #ifedf H5 -->
<view>只在H5页面中显示</view>
<!-- #endif -->

<!-- #ifedf MP-WEIXIN -->
<view>只在微信小程序中显示</view>
<!-- #endif -->

script中

methods: {

  alertMessage() {
    // #ifedf H5
    alert('这一段只会在h5中执行')
    // #endif

    // #ifedf MP-WEIXIN
    alert('这一段只会在微信小程序中执行')
    // #endif
  }

}

style中

/* 在h5中使用这一套css */
/* #ifedf H5 */
.container {
  color: red;
  view {
    .....
  }
}
/* #endif */

/* 在微信小程序中使用这一套css */
/* #ifedf MP-WEIXIN */
.container {
  color: green;
  view {
    .....
  }
}
/* #endif */

posted on 2022-09-11 00:55  In-6026  阅读(75)  评论(0编辑  收藏  举报

导航