微信小程式把玩(三十八)獲取裝置資訊 API
阿新 • • 發佈:2019-01-30
獲取裝置資訊這裡分為四種,
主要屬性:
網路資訊wx.getNetWorkType,
系統資訊wx.getSystemInfo,
- 重力感應資料wx.onAccelerometerChange,
- 羅盤資料wx.onCompassChange
wxml
<button type="primary" bindtap="getNetWorkType">獲取網路型別</button>
<button type="primary" bindtap="getSystemInfo">獲取裝置資訊</button>
<button type="primary" bindtap="onAccelerometerChange">監聽重力感應資料</button>
<button type="primary" bindtap="onCompassChange">監聽羅盤資料</button>
js
Page({
data:{
text:"Page system"
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉所帶來的引數
},
/**
* 獲取當前網路狀態
*/
getNetWorkType: function () {
wx.getNetworkType({
success: function(res) {
console.log(res)
}
})
},
/**
* 獲取系統資訊
*/
getSystemInfo: function() {
wx.getSystemInfo({
success: function(res) {
console.log(res)
}
})
},
/**
* 監聽重力感應資料
* - 帶on開頭的都是監聽接收一個callback
*/
onAccelerometerChange: function() {
wx.onAccelerometerChange(function(res) {
console.log(res)
})
},
/**
* 監聽羅盤資料
*/
onCompassChange: function() {
wx.onCompassChange(function(res) {
console.log(res)
})
},
onReady:function(){
// 頁面渲染完成
},
onShow:function(){
// 頁面顯示
},
onHide:function(){
// 頁面隱藏
},
onUnload:function(){
// 頁面關閉
}
})