在做微信小程序的过程中,会遇到怎么获取系统信息,如微信版本号、微信操作系统版本、客户端平台、用户设置字体大小、手机型号和品牌等。下面利用几个实例说明,操作如下:
.wxml布局文件代码
手机型号:{{mobileModel}}手机像素比:{{mobileePixelRatio}}窗口宽度:{{windowWidth}}窗口高度:{{windowHeight}}微信设置的语言:{{language}}微信版本号:{{version}}
.js逻辑文件代码
var app = getApp()
Page({
data: {
mobileModel:'',
mobileePixelRatio:'',
windowWidth:'',
windowHeight:'',
language:'',
version:''
},
onLoad: function () {
var that=this;
wx.getSystemInfo({
success: function(res) {
that.setData({
mobileModel:res.model,
mobileePixelRatio:res.pixelRatio,
windowWidth:res.windowWidth,
windowHeight:res.windowHeight,
language:res.language,
version:res.version
})
}
})
}
})