我是在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({

本文介绍了如何在微信小程序中实现版本自动检查和更新,重点是在app.js中的实现过程,并建议在更新过程中配合加载动图提升用户体验。
最低0.47元/天 解锁文章
2072

被折叠的 条评论
为什么被折叠?



