main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import App from './App'
  2. // import $wxApi from "./wxapi.js";
  3. // Vue.prototype.$wxApi = $wxApi;
  4. //微信支付封装
  5. // import $pay from "./pay.js";
  6. // Vue.prototype.$pay = $pay
  7. // #ifndef VUE3
  8. import Vue from 'vue'
  9. Vue.config.productionTip = false
  10. App.mpType = 'app'
  11. try {
  12. function isPromise(obj) {
  13. return (
  14. !!obj &&
  15. (typeof obj === "object" || typeof obj === "function") &&
  16. typeof obj.then === "function"
  17. );
  18. }
  19. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  20. uni.addInterceptor({
  21. returnValue(res) {
  22. if (!isPromise(res)) {
  23. return res;
  24. }
  25. return new Promise((resolve, reject) => {
  26. res.then((res) => {
  27. if (res[0]) {
  28. reject(res[0]);
  29. } else {
  30. resolve(res[1]);
  31. }
  32. });
  33. });
  34. },
  35. });
  36. } catch (error) { }
  37. import uView from '@/uni_modules/uview-ui'
  38. Vue.use(uView)
  39. import { commonConfig } from './common/config';
  40. Vue.prototype.$commonConfig = commonConfig;
  41. Vue.prototype.$isDevelop = commonConfig.baseUrl.includes('gztjy');
  42. import './utils/filter'
  43. import store from '@/store';
  44. // 引入uView提供的对vuex的简写法文件
  45. let vuexStore = require('@/store/$u.mixin.js');
  46. Vue.mixin(vuexStore);
  47. const app = new Vue({
  48. ...App,
  49. store
  50. })
  51. //uviewui v1
  52. // // http拦截器,将此部分放在new Vue()和app.$mount()之间,才能App.vue中正常使用
  53. // import httpInterceptor from '@/common/http.interceptor.js';
  54. // Vue.use(httpInterceptor, app);
  55. // 引入请求封装,将app参数传递到配置中
  56. require('./common/request.js')(app)
  57. // http接口API抽离,免于写url或者一些固定的参数
  58. import httpApi from '@/common/http.api.js';
  59. Vue.use(httpApi, app);
  60. app.$mount()
  61. // #endif
  62. // #ifdef VUE3
  63. import { createSSRApp } from 'vue'
  64. export function createApp() {
  65. const app = createSSRApp(App)
  66. return {
  67. app
  68. }
  69. }
  70. // #endif