小程序全局属性和方法

全局属性方法

  enablePullDownRefresh 类型 : boolean 描述:是否开启全局的下拉刷新

  onPullDownRefresh() :类型:function 描述:监听用户下拉刷新事件。说明:

      监听用户下拉刷新事件。

  wx.stopPullDownRefresh(Object object) : 描述: 停止当前页面下拉刷新。示例:    

      Page({
        onPullDownRefresh () {
          wx.stopPullDownRefresh()
        }
      })

  permission : 给小程序配置全局定位(获取地理位置):

    {

    "pages": ["pages/index/index"],

        "permission": {
          "scope.userLocation": {
          "desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
         }
       }
    }


其中:


js文件中引用获取地理位置的
wx.getLocation() 方法,获取当前的地理位置、速度
openLocation() 方法 使用微信内置地图查看位置:
属性: latitude 纬度 longitude 经度 scale 缩放比例,范围5~18 ....
示例代码:
wx:getLocation ({
type:'gcJ02',
success (res) {
const latitude = res.latitude
const longitude = res.longitude
wx.openLocation ({
latitude,
longitude,
scale:18
})
}
})

wx.getStorageSync():本地缓存,例如:这个可以解决微信小程序的记录缓存,入输入框的搜索历史记录

  应用:    

    setStorageSync():设置要缓存的数据

    getStorageSync():取出缓存的数据

    如果使用同步的话(Sync)参数不能使对象而是字符串。并且是键值对的形式也就是:setStorageSync(key, value) 而不是 setStorageSync({key: "XXX", value: "XXX"})

    所以如果要使用对象的形式就只能使用异步的方式 get/setStorage({key: "XXX", value: "XXX"})

关于setStorageSync()、getStorageSync() 待续。。。。

  获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。

  其中,Object.success 成功回调函数:属性 :authSetting 描述: 用户授权结果,示例: 

      wx.getSetting({
        success (res) {
          console.log(res.authSetting)
          // res.authSetting = {
          //   "scope.userInfo": true,
          //   "scope.userLocation": true
          // }
        }
     })