App.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. if (uni.canIUse('getUpdateManager')) {
  5. const updateManager = uni.getUpdateManager()
  6. updateManager.onCheckForUpdate(function(res) {
  7. console.log('onCheckForUpdate====', res)
  8. // 请求完新版本信息的回调
  9. if (res.hasUpdate) {
  10. console.log('res.hasUpdate====')
  11. updateManager.onUpdateReady(function() {
  12. uni.showModal({
  13. title: '更新提示',
  14. content: '新版本已经准备好,是否重启应用?',
  15. success: function(res) {
  16. console.log('success====', res)
  17. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  18. if (res.confirm) {
  19. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  20. updateManager.applyUpdate()
  21. }
  22. }
  23. })
  24. })
  25. updateManager.onUpdateFailed(function() {
  26. // 新的版本下载失败
  27. uni.showModal({
  28. title: '已经有新版本了哟~',
  29. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  30. })
  31. })
  32. }
  33. })
  34. }
  35. },
  36. onShow: function() {
  37. },
  38. onHide: function() {
  39. console.log('App Hide')
  40. }
  41. }
  42. </script>
  43. <style lang="scss">
  44. @import "uview-ui/index.scss";
  45. page {
  46. background-color: #f8f8f8;
  47. width: 100%;
  48. }
  49. @import "@/components/colorui/main.css";
  50. @import "@/components/colorui/icon.css";
  51. </style>