App.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <script>
  2. import $http from '@/utils/request.js'
  3. export default {
  4. globalData: {
  5. userInfo: {},
  6. },
  7. onLaunch: function() {
  8. uni.hideTabBar()
  9. },
  10. onShow: function() {
  11. this.updateManager()
  12. },
  13. onHide: function() {
  14. },
  15. methods: {
  16. updateManager() {
  17. const updateManager = uni.getUpdateManager();
  18. updateManager.onCheckForUpdate(res => {
  19. // 请求完新版本信息的回调
  20. // console.log(res.hasUpdate)
  21. })
  22. updateManager.onUpdateReady(() => {
  23. uni.showModal({
  24. title: '更新提示',
  25. content: '新版本已经准备好,即将重启应用',
  26. showCancel: false,
  27. success(res) {
  28. if (res.confirm) {
  29. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  30. updateManager.applyUpdate()
  31. }
  32. }
  33. })
  34. })
  35. updateManager.onUpdateFailed(() => {
  36. // 新的版本下载失败
  37. uni.showModal({
  38. title: '更新提示',
  39. content: '新版本下载失败',
  40. showCancel: false
  41. })
  42. })
  43. },
  44. }
  45. }
  46. </script>
  47. <style lang="scss">
  48. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  49. @import "@/uni_modules/uview-ui/index.scss";
  50. // 设置整个项目的背景色
  51. page {
  52. background-color: #f8f8f8;
  53. font-size: 14px;
  54. color: #333;
  55. }
  56. view {
  57. box-sizing: border-box;
  58. word-break: break-all;
  59. }
  60. .container {
  61. font-size: 14px;
  62. color: #333;
  63. padding: 10px;
  64. }
  65. .flex {
  66. display: flex;
  67. align-items: center;
  68. justify-content: center;
  69. }
  70. </style>