推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.3 KiB

4 months ago
4 months ago
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. import './uni.promisify.adaptor'
  5. Vue.config.productionTip = false
  6. App.mpType = 'app'
  7. import store from '@/store/store'
  8. import './config'
  9. import './utils/index.js'
  10. import mixinConfigList from '@/mixins/configList.js'
  11. Vue.mixin(mixinConfigList)
  12. //组件注册
  13. import configPopup from '@/components/config/configPopup.vue'
  14. import navbar from '@/components/base/navbar.vue'
  15. Vue.component('configPopup',configPopup)
  16. Vue.component('navbar',navbar)
  17. // #ifdef H5
  18. import { fixH5Router } from '@/utils/h5-router-fix.js'
  19. import { fixUrlParams } from '@/utils/h5-fix.js'
  20. // 立即执行 H5 修复
  21. fixH5Router();
  22. fixUrlParams();
  23. // 设置 Vue 全局错误处理器
  24. Vue.config.errorHandler = function (err, vm, info) {
  25. // 忽略已知的 H5 兼容性错误
  26. if (err.message && (
  27. err.message.includes("Cannot read property 'meta'") ||
  28. err.message.includes('replaceState') ||
  29. err.message.includes('showTabBar') ||
  30. err.message.includes('History')
  31. )) {
  32. console.warn('H5兼容性错误已忽略:', err.message);
  33. return;
  34. }
  35. // 其他错误正常输出
  36. console.error('Vue Error:', err, vm, info);
  37. };
  38. import share from '@/utils/share.js'
  39. share()
  40. // #endif
  41. // H5 环境下的特殊处理
  42. // #ifdef H5
  43. Vue.config.silent = false;
  44. // 在创建 Vue 实例前添加额外的错误处理
  45. const originalConsoleError = console.error;
  46. console.error = function(...args) {
  47. // 过滤掉一些已知的 H5 兼容性错误
  48. const message = args.join(' ');
  49. if (message.includes("Cannot read property 'meta'") ||
  50. message.includes('replaceState') ||
  51. message.includes('showTabBar')) {
  52. console.warn('H5兼容性警告:', message);
  53. return;
  54. }
  55. originalConsoleError.apply(console, args);
  56. };
  57. // #endif
  58. try {
  59. const app = new Vue({
  60. ...App,
  61. store,
  62. })
  63. app.$mount()
  64. } catch(e) {
  65. console.error('Vue 应用启动失败:', e);
  66. // #ifdef H5
  67. // H5 环境下的降级处理
  68. setTimeout(() => {
  69. try {
  70. const app = new Vue({
  71. ...App,
  72. store,
  73. })
  74. app.$mount()
  75. } catch(retryError) {
  76. console.error('Vue 应用重试启动失败:', retryError);
  77. }
  78. }, 100);
  79. // #endif
  80. }
  81. // #endif
  82. // #ifdef VUE3
  83. import {
  84. createSSRApp
  85. } from 'vue'
  86. export function createApp() {
  87. const app = createSSRApp(App)
  88. return {
  89. app
  90. }
  91. }
  92. // #endif