uniapp 小程序 更新提示
项目记录项目记录项目记录项目记录项目记录项目记录
app.vue 里面的onShow 复制进去就会生效
// #ifdef MP-WEIXIN
if (wx.canIUse('getUpdateManager')) {
const wxUpdateManager = wx.getUpdateManager();
wxUpdateManager.onCheckForUpdate((res) => {
console.log(res);
if (res.hasUpdate) {
wxUpdateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
wxUpdateManager.applyUpdate();
}
}
})
})
wxUpdateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新失败',
})
})
}
})
}
// #endif