小程序常用方法封装

// 设置缓存
function setItem(key, value) {
  wx.setStorageSync(key, value)
}
// 获取缓存
function getItem(key) {
  return wx.getStorageSync(key)
}
// 移除缓存
function removeItem(key) {
  wx.removeStorageSync(key)
}
// 清除缓存
function clearAll() {
  wx.clearStorageSync()
}
//下拉刷新
function pullDownRefresh() {
  wx.startPullDownRefresh()
}
//滚动事件
function pageScrollTo(scrollTop,duration) {
  wx.pageScrollTo({
    scrollTop, //滚动据顶部距离
    duration  //滚动时间
  })
}
//打开蓝牙设备
function openBluetooth() {
  return new Promise((resolve, reject) => {
    wx.openBluetoothAdapter({
      success (res) {
        resolve (res)
      },
      fail (res) {
        wx.showModal({
             content: '请开启手机蓝牙后再试'
         })
     }
    })
 })
}
//开始搜索蓝牙设备
function startBluetooth() {
  return new Promise((resolve, reject) => {
    wx.startBluetoothDevicesDiscovery({
      success (res) {
        console.log(res);
        resolve (res)
      },
      fail (res) {
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章