微信小程序 获取设备信息 API实例详解
2019/6/27 21:44:20
本文主要是介绍微信小程序 获取设备信息 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(){ // 页面关闭 } })
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
这篇关于微信小程序 获取设备信息 API实例详解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-06vue 新建功能多条数据(还没和后端交互)还能看详情 数据是前端缓存到本地吗?-icode9专业技术文章分享
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode