1.1 小程序官方文档:

(1)小程序线上版本更新官方文档(updateManager对象管理线上版本更新):https://developers.weixin.qq....
(2)小程序强制更新:
https://developers.weixin.qq....

2.1 参考博客:

微信小程序版本自动更新:https://www.jianshu.com/p/4f5...

3.1 关键知识点:

(1)小程序热启动
(2)小程序冷启动
(3)updateManager对象
(4)利用wx.canIuse( )方法判断getUpdateManger
(5)UpdateManager.onCheckForUpdate(function callback)回调函数监听是否后台有更新版本
(6)UpdateManager.onUpdateReady(function callback)监听版本成功下载后利用UpdateManager.applyUpdate()重启小程序
(7)UpdateManager.onUpdateFailed(function callback)监听版本更新失败后的回调
(8)微信小程序在冷更新并且有新版本的情况下才能重启

4.1 下图是更新的流程:

5.1 代码展示:

 if (wx.canIUse('getUpdateManager')) {      const updateManager = wx.getUpdateManager()      console.log(updateManager);      updateManager.onCheckForUpdate(function (res) {        // 请求完新版本信息的回调        console.log(res);        if (res.hasUpdate) {          updateManager.onUpdateReady(function () {            wx.showModal({              title: '更新提示',              content: '新版本已经准备好,是否重启应用?',              success: function (res) {                // res: {errMsg: "showModal: ok", cancel: false, confirm: true}                if (res.confirm) {                  // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启                  updateManager.applyUpdate()                }              }            })          })          updateManager.onUpdateFailed(function () {            // 新的版本下载失败            wx.showModal({              title: '已经有新版本了哟~',              content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'            })          })        }      })    }

5.1 模拟更新版本:

第一步:点击普通编译并添加编译模式

第二步:设定更新模式并勾选下一次编译时更新,点击确认

第四步:编译成功后,跳出更新页面