main.js 958 B

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