微信小程序获取设备信息api示例

 4118

微信小程序获取设备信息api示例,直接上代码:

  1. <button type="primary" bindtap="getNetWorkType">获取网络类型</button>
  2. <button type="primary" bindtap="getSystemInfo">获取设备信息</button>
  3. <button type="primary" bindtap="onAccelerometerChange">监听重力感应数据</button>
  4. <button type="primary" bindtap="onCompassChange">监听罗盘数据</button>

js

  1. Page({
  2.     data:{
  3.         text:"Page system"
  4.     },
  5.     onLoad:function(options){
  6.         // 页面初始化 options为页面跳转所带来的参数
  7.     },
  8.     /**
  9.     * 获取当前网络状态
  10.     */
  11.     getNetWorkType: function() {
  12.         wx.getNetworkType({
  13.             success: function(res) {
  14.                 console.log(res)
  15.             }
  16.         })
  17.     },
  18.     /**
  19.     *  获取系统信息
  20.     */
  21.     getSystemInfo: function() {
  22.         wx.getSystemInfo({
  23.             success: function(res) {
  24.                 console.log(res)
  25.             }
  26.         })
  27.     },
  28.     /**
  29.     *  监听重力感应数据     
  30.     *      - 带on开头的都是监听接收一个callback
  31.     */
  32.     onAccelerometerChange: function() {
  33.         wx.onAccelerometerChange(function(res) {
  34.             console.log(res)
  35.         })
  36.     },
  37.     /**
  38.     *  监听罗盘数据
  39.     */
  40.     onCompassChange: function() {
  41.         wx.onCompassChange(function(res) {
  42.             console.log(res)
  43.         })
  44.     },
  45.     onReady:function(){
  46.         // 页面渲染完成
  47.     },
  48.     onShow:function(){
  49.         // 页面显示
  50.     },
  51.     onHide:function(){
  52.         // 页面隐藏
  53.     },
  54.     onUnload:function(){
  55.         // 页面关闭
  56.     }
  57. })


本文网址:https://www.zztuku.com/index.php/detail-9798.html
站长图库 - 微信小程序获取设备信息api示例
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐