main.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import App from './App'
  2. import store from './store'
  3. // main.js,注意要在use方法之后执行
  4. import uView from 'uview-ui'
  5. Vue.use(uView)
  6. // uni.$u.config.unit = 'rpx'
  7. // 如此配置即可
  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. store
  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