main.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Vue.component('reverseBack', reverseBack)
  13. Vue.component('closeIocn', closeIocn)
  14. // 如此配置即可
  15. // #ifndef VUE3
  16. import Vue from 'vue'
  17. Vue.config.productionTip = false
  18. App.mpType = 'app'
  19. try {
  20. function isPromise(obj) {
  21. return (
  22. !!obj &&
  23. (typeof obj === "object" || typeof obj === "function") &&
  24. typeof obj.then === "function"
  25. );
  26. }
  27. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  28. uni.addInterceptor({
  29. returnValue(res) {
  30. if (!isPromise(res)) {
  31. return res;
  32. }
  33. return new Promise((resolve, reject) => {
  34. res.then((res) => {
  35. if (res[0]) {
  36. reject(res[0]);
  37. } else {
  38. resolve(res[1]);
  39. }
  40. });
  41. });
  42. },
  43. });
  44. } catch (error) {}
  45. const app = new Vue({
  46. ...App,
  47. store
  48. })
  49. app.$mount()
  50. // #endif
  51. // #ifdef VUE3
  52. import {
  53. createSSRApp
  54. } from 'vue'
  55. export function createApp() {
  56. const app = createSSRApp(App)
  57. return {
  58. app
  59. }
  60. }
  61. // #endif