main.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import App from './App'
  2. import uView from './uni_modules/vk-uview-ui';
  3. import * as Pinia from 'pinia';
  4. import plugins from './plugins' // plugins
  5. // #ifndef VUE3
  6. import Vue from 'vue'
  7. Vue.config.productionTip = false
  8. App.mpType = 'app'
  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. const app = new Vue({
  36. ...App
  37. })
  38. app.$mount()
  39. // #endif
  40. // #ifdef VUE3
  41. import { createSSRApp } from 'vue'
  42. export function createApp() {
  43. const app = createSSRApp(App)
  44. app.use(uView)
  45. app.use(Pinia.createPinia());
  46. app.use(plugins)
  47. return {
  48. app,
  49. Pinia
  50. }
  51. }
  52. // #endif