3.小程序常用API总结

1.加载

//显示加载框
wx.showLoading({
	title: '加载中',
})
//隐藏加载框
wx.hideLoading()

2.Toast


wx.showToast({
  title: '功能暂未开放!',
  icon: 'none', success
  duration: 2000
})

3.延时

setTimeout(function () {
  wx.hideLoading()
}, 2000)

4.数据缓存

//1.设置缓存
wx.setStorageSync('key', 'value')

//2.获取缓存
wx.getStorageSync('key')

//3.移除缓存
wx.removeStorage({
key: 'key',
success: function(res) {
console.log(res.data)
}})

4.清除缓存
wx.clearStorage()

5.对话框

wx.showModal({
    title: '复制该链接',
    content: '完成后请手动打开浏览器,是否继续?' + link,
    success: function (res) {
      if (res.confirm) {
        wx.setClipboardData({
          data: link,
          success: function () {
            wx.showToast({
              title: '复制成功',
              duration: 1500,
            })

          },
          fail: function () {
            wx.showToast({
              title: '复制失败',
              icon: 'none',
              duration: 500,
            })
          }
        })
      } else if (res.cancel) {
        wx.showToast({
          title: '取消复制',
          icon: 'none',
          duration: 500,
        })
      }
    }
  })

6.动态设置标题

wx.setNavigationBarTitle({

title: '当前页面'

}

7.跳转

//1.保留当前页面,跳转到应用内的某个页面
wx.navigateTo({url: 'test?id=1'})

//2.关闭当前页面,跳转到应用内的某个页面
wx.redirectTo({ url: 'test?id=1'})

8.获取系统信息

wx.getSystemInfo({

success: function(res) {

console.log(res.model)

console.log(res.pixelRatio)

console.log(res.windowWidth)

console.log(res.windowHeight)

console.log(res.language)

console.log(res.version)

}

})

9.获取位置

wx.getLocation({

type: 'wgs84',

success: function(res) {

var latitude = res.latitude

var longitude = res.longitude

var speed = res.speed

var accuracy = res.accuracy

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值