main.js 887 B

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