uniapp小程序更新版本提醒

ゞ 浴缸里的玫瑰 2022-09-15 12:21 378阅读 0赞

在App.vue的onLaunch中写

  1. onLaunch(options) {
  2. if (wx.canIUse('getUpdateManager')) {
  3. const updateManager = wx.getUpdateManager()
  4. updateManager.onCheckForUpdate(function (res) {
  5. // 请求完新版本信息的回调
  6. if (res.hasUpdate) {
  7. console.log('res.hasUpdate====')
  8. updateManager.onUpdateReady(function () {
  9. wx.showModal({
  10. title: '更新提示',
  11. content: '新版本已经准备好,是否重启应用?',
  12. success: function (res) {
  13. console.log('success====', res)
  14. if (res.confirm) {
  15. updateManager.applyUpdate()
  16. }
  17. }
  18. })
  19. })
  20. updateManager.onUpdateFailed(function () {
  21. // 新的版本下载失败
  22. wx.showModal({
  23. title: '已经有新版本了哟~',
  24. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索(你的小程序名字)小程序打开哟~',
  25. showCancel:false
  26. })
  27. })
  28. }
  29. })
  30. }
  31. }

发表评论

表情:
评论列表 (有 0 条评论,378人围观)

还没有评论,来说两句吧...

相关阅读

    相关 微信程序版本更新

    小程序先提交了一个版本,但是用的时候发现了一些问题需要及时的更新,这时候就要发布新版本。如何让用户自己的小程序也更新到最新版本呢? 一、运行机制 小程序启动会有两种情况