main.js 1.2 KB

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