本文實例講述了微信小程序獲取手機系統信息的方法。分享給大家供大家參考,具體如下:
1、效果展示
2、關鍵代碼
index.wxml布局文件代碼
<view>手機型號:{{mobileModel}}</view> <view>手機像素比:{{mobileePixelRatio}}</view> <view>窗口寬度:{{windowWidth}}</view> <view>窗口高度:{{windowHeight}}</view> <view>微信設置的語言:{{language}}</view> <view>微信版本號:{{version}}</view>
index.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 }) } }) } })
這里通過wx.getSystemInfo函數來獲取手機系統信息。具體參數說明與用法還可參考官網:https://mp.weixin.qq.com/debug/wxadoc/dev/api/systeminfo.html#wxgetsysteminfoobject
3、源代碼點擊此處本站下載。
希望本文所述對大家微信小程序開發有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。