官网api: https://developers.weixin.qq.com/miniprogram/dev/api/base/update/wx.getUpdateManager.html

app.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
onShow : function() {
this.checkForUpdate()
},
// 检查版本更新
checkForUpdate(){
wx.getUpdateManager().onCheckForUpdate(res => {
console.log('请求版本更新信息',res);
if (res.hasUpdate) {
// 新版本下载成功
wx.getUpdateManager().onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,点击确定重启小程序',
showCancel: false,
success(res) {
if (res.confirm) {
//准备完毕 强制更新
wx.getUpdateManager().applyUpdate()
}
}
})
})
}
})
// 新版本下载失败
wx.getUpdateManager().onUpdateFailed(res => {
console.error('新版本下载失败',res)
//
})
},

效果