main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import App from './App'
  2. import store from './store'
  3. // main.js,注意要在use方法之后执行
  4. import uView from 'uview-ui'
  5. Vue.use(uView)
  6. uni.$u.config.unit = 'rpx'
  7. import initialize from "@/utils/initialize.js"
  8. Vue.use(initialize);
  9. // 全局加载组件
  10. import reverseBack from "@/components/headModules/reverse-back.vue"
  11. import closeIocn from "@/components/headModules/close.vue"
  12. import headCollect from "@/components/headModules/collect.vue"
  13. Vue.component('reverseBack', reverseBack)
  14. Vue.component('closeIocn', closeIocn)
  15. Vue.component('headCollect', headCollect)
  16. // 如此配置即可
  17. // #ifndef VUE3
  18. import Vue from 'vue'
  19. Vue.config.productionTip = false
  20. App.mpType = 'app'
  21. try {
  22. function isPromise(obj) {
  23. return (
  24. !!obj &&
  25. (typeof obj === "object" || typeof obj === "function") &&
  26. typeof obj.then === "function"
  27. );
  28. }
  29. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  30. uni.addInterceptor({
  31. returnValue(res) {
  32. if (!isPromise(res)) {
  33. return res;
  34. }
  35. return new Promise((resolve, reject) => {
  36. res.then((res) => {
  37. if (res[0]) {
  38. reject(res[0]);
  39. } else {
  40. resolve(res[1]);
  41. }
  42. });
  43. });
  44. },
  45. });
  46. } catch (error) {}
  47. const app = new Vue({
  48. ...App,
  49. store
  50. })
  51. app.$mount()
  52. // #endif
  53. // #ifdef VUE3
  54. import {
  55. createSSRApp
  56. } from 'vue'
  57. export function createApp() {
  58. const app = createSSRApp(App)
  59. return {
  60. app
  61. }
  62. }
  63. // #endif