main.js 910 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import App from './App'
  2. import './public.scss';
  3. // #ifndef VUE3
  4. import Vue from 'vue'
  5. Vue.config.productionTip = false
  6. App.mpType = 'app'
  7. try {
  8. function isPromise(obj) {
  9. return (
  10. !!obj &&
  11. (typeof obj === "object" || typeof obj === "function") &&
  12. typeof obj.then === "function"
  13. );
  14. }
  15. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  16. uni.addInterceptor({
  17. returnValue(res) {
  18. if (!isPromise(res)) {
  19. return res;
  20. }
  21. return new Promise((resolve, reject) => {
  22. res.then((res) => {
  23. if (res[0]) {
  24. reject(res[0]);
  25. } else {
  26. resolve(res[1]);
  27. }
  28. });
  29. });
  30. },
  31. });
  32. } catch (error) {}
  33. const app = new Vue({
  34. ...App
  35. })
  36. app.$mount()
  37. // #endif
  38. // #ifdef VUE3
  39. import {
  40. createSSRApp
  41. } from 'vue'
  42. import uviewPlus from '@/uview-plus'
  43. export function createApp() {
  44. const app = createSSRApp(App)
  45. app.use(uviewPlus)
  46. return {
  47. app
  48. }
  49. }
  50. // #endif