App.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script>
  2. export default {
  3. onLaunch: async function(e) {
  4. // 检测是否可以调用getUpdateManager检查更新
  5. if (!uni.canIUse("getUpdateManager")) return;
  6. const updateManager = uni.getUpdateManager();
  7. // console.log(updateManager)
  8. // 获取全局唯一的版本更新管理器,用于管理小程序更新
  9. updateManager.onCheckForUpdate(function(res) {
  10. // 监听向微信后台请求检查更新结果事件
  11. console.log("是否有新版本:" + res.hasUpdate);
  12. if (res.hasUpdate) {
  13. //如果有新版本
  14. // 小程序有新版本,会主动触发下载操作
  15. updateManager.onUpdateReady(function() {
  16. //当新版本下载完成,会进行回调
  17. uni.showModal({
  18. title: '更新提示',
  19. content: '新版本已经准备好,单击确定重启小程序',
  20. showCancel: false,
  21. success: function(res) {
  22. if (res.confirm) {
  23. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启小程序
  24. updateManager.applyUpdate();
  25. }
  26. }
  27. })
  28. })
  29. // 小程序有新版本,会主动触发下载操作
  30. updateManager.onUpdateFailed(function() {
  31. //当新版本下载失败,会进行回调
  32. uni.showModal({
  33. title: '提示',
  34. content: '检查到有新版本,但下载失败,请稍后尝试',
  35. showCancel: false,
  36. })
  37. })
  38. }
  39. });
  40. },
  41. onShow: function() {},
  42. onHide: function() {console.log('App Hide')},
  43. globalData: {
  44. userinfo: null,
  45. token:'',
  46. },
  47. }
  48. </script>
  49. <style lang="scss">
  50. /*每个页面公共css */
  51. @import "@/uni_modules/uview-ui/index.scss";
  52. @import "colorui/main.css";
  53. @import "colorui/icon.css";
  54. </style>