App.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script>
  2. export default {
  3. /**
  4. * 全局变量
  5. */
  6. globalData: {
  7. },
  8. /**
  9. * 初始化完成时触发
  10. */
  11. onLaunch() {
  12. // 小程序主动更新
  13. this.updateManager()
  14. },
  15. methods: {
  16. /**
  17. * 小程序主动更新
  18. */
  19. updateManager() {
  20. const updateManager = uni.getUpdateManager();
  21. updateManager.onCheckForUpdate(res => {
  22. // 请求完新版本信息的回调
  23. // console.log(res.hasUpdate)
  24. })
  25. updateManager.onUpdateReady(() => {
  26. uni.showModal({
  27. title: '更新提示',
  28. content: '新版本已经准备好,即将重启应用',
  29. showCancel: false,
  30. success(res) {
  31. if (res.confirm) {
  32. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  33. updateManager.applyUpdate()
  34. }
  35. }
  36. })
  37. })
  38. updateManager.onUpdateFailed(() => {
  39. // 新的版本下载失败
  40. uni.showModal({
  41. title: '更新提示',
  42. content: '新版本下载失败',
  43. showCancel: false
  44. })
  45. })
  46. }
  47. }
  48. }
  49. </script>
  50. <style lang="scss">
  51. /* 引入uView库样式 */
  52. @import "uview-ui/index.scss";
  53. </style>
  54. <style>
  55. /* 项目基础样式 */
  56. @import "./app.scss";
  57. .uni-app--showlayout+uni-tabbar.uni-tabbar-bottom,
  58. .uni-app--showlayout+uni-tabbar.uni-tabbar-bottom .uni-tabbar,
  59. .uni-app--showlayout+uni-tabbar.uni-tabbar-top,
  60. .uni-app--showlayout+uni-tabbar.uni-tabbar-top .uni-tabbar {
  61. left: var(--window-left);
  62. right: var(--window-right);
  63. }
  64. </style>