main.js 941 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. import './uni.promisify.adaptor'
  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 { createSSRApp } from 'vue'
  40. export function createApp() {
  41. const app = createSSRApp(App)
  42. return {
  43. app
  44. }
  45. }
  46. // #endif