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
}