main.js 1.0 KB

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