main.js 1.2 KB

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