main.js 1.1 KB

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