我是在app.js里进行版本检查
(页面最好有加载动图效果)
onLaunch: function() {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs);
//判断微信版本是否 兼容小程序更新机制API的使用
//创建 UpdateManager 实例
const updateManager = wx.getUpdateManager();
//检测版本更新
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
//监听小程序有版本更新事件
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启 ( 此处进行了自动更新操作)
wx.showModal({
title: '提示',
content: '检测到有新版本,是否更新?',
success: function(res) {
if (res.confirm) {
wx.showLoading({
title: '更新中...',
})
updateManager.onUpdateReady(function() {
wx.hideLoading();
updateManager.applyUpdate();
})
} else if (res.cancel) {
wx.showToast({