App.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. const updateManager = uni.getUpdateManager() // 小程序版本更新管理器
  5. updateManager.onCheckForUpdate(res => { // 检测新版本后的回调
  6. if(res.hasUpdate) { // 如果有新版本提醒并进行强制升级
  7. uni.showModal({
  8. content: '新版本已经准备好,是否重启应用?',
  9. showCancel: false,
  10. confirmText: '确定',
  11. confirmColor:'#3e90fa',
  12. success: res => {
  13. if (res.confirm) {
  14. updateManager.onUpdateReady(res => { // 新版本下载完成的回调
  15. updateManager.applyUpdate() // 强制当前小程序应用上新版本并重启
  16. })
  17. updateManager.onUpdateFailed(res => { // 新版本下载失败的回调
  18. // 新版本下载失败,提示用户删除后通过冷启动重新打开
  19. uni.showModal({
  20. content: '下载失败,请删除当前小程序后重新搜索打开',
  21. showCancel: false,
  22. confirmText: '我知道了'
  23. })
  24. })
  25. }
  26. }
  27. })
  28. }
  29. })
  30. },
  31. onShow: function() {
  32. },
  33. onHide: function() {
  34. }
  35. }
  36. </script>
  37. <style>
  38. /*每个页面公共css */
  39. </style>