小程序适配 IphoneX

===>App.js

  globalData:{
      isPhoneX: 0
  },
  onLauch:function(){
     this.checkMobilePhone();
  },
  checkMobilePhone:function(){
     var self = this;
     wx.getSystemInfo({
        success: function (e) {
           var a = e.model;
           if (-1 != a.search("iPhone X") || -1 != a.search("iPhone XS")){//找到
              self.globalData.isIphoneX = 1
           }else{
              self.globalData.isIphoneX = 0
           }
        }
     })
  },

==>page.js

const app = getApp()
data:{
  isIphoneX:app.globalData.isIphoneX
}

==>page.wxml

class="{{isIponeX?'IphoneX的class':'默认样式的class' }}"

你可能感兴趣的:(小程序适配 IphoneX)