當我們把微信小程序提交審核,通過后進行發(fā)布,如果用戶本地使用小程序有時就會出現(xiàn)緩存,打開的小程序還是舊的版本。遇到這個問題可以通過刪除小程序并重新進入的方式來清除緩存,但這樣明顯不是個好辦法
利用uni-app中的uni.getUpdateManager()來處理
官網(wǎng)鏈接 https://uniapp.dcloud.net.cn/api/other/update.html#getupdatemanager
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
// 請求完新版本信息的回調(diào)
console.log(res.hasUpdate);
});
updateManager.onUpdateReady(function (res) {
uni.showModal({
title: '更新提示',
content: '新版本已經(jīng)準備好,是否重啟應(yīng)用?',
success(res) {
if (res.confirm) {
// 新的版本已經(jīng)下載好,調(diào)用 applyUpdate 應(yīng)用新版本并重啟
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(function (res) {
// 新的版本下載失敗
});