微信小程序 获取设备信息 API实例详解
更新时间:2016年10月02日 10:00:40 作者:顺子_RTFSC
这篇文章主要介绍了微信小程序 获取设备信息 API实例详解的相关资料,需要的朋友可以参考下

获取设备信息这里分为四种,
主要属性:
网络信息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(){
// 页面关闭
}
})
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章
微信小程序上滑加载下拉刷新(onscrollLower)分批加载数据(二)
这篇文章主要介绍了微信小程序上滑加载下拉刷新(onscrollLower)分批加载数据的相关资料,需要的朋友可以参考下2017-05-05
JavaScript中时间格式化新思路toLocaleString()
这篇文章主要介绍了JavaScript中时间格式化新思路toLocaleString(),研究Object对象的时候,看到了 toLocaleString() 这个方法可以很简单的实现时间格式化,下面来看看toLocaleString() 的详细内容吧,需要的朋友可以参考一下2021-11-11
Intl对象DateTimeFormat ListFormat RelativeTimeFormat使用讲解
这篇文章主要为大家介绍了Intl对象DateTimeFormat ListFormat RelativeTimeFormat使用讲解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-06-06


最新评论