main.js 998 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Vue from 'vue';
  2. import App from './App';
  3. import store from '@/store';
  4. App.mpType = 'app';
  5. // global mixin
  6. import GlobalMixin from '@/mixin/index.js';
  7. Vue.mixin(GlobalMixin);
  8. // router
  9. import { router, RouterMount } from '@/router';
  10. Vue.use(router);
  11. // uView
  12. import uView from 'uview-ui';
  13. Vue.use(uView);
  14. // cache
  15. import cache from '@/mixin/cache';
  16. Vue.mixin(cache);
  17. Vue.config.productionTip = false;
  18. App.mpType = 'app';
  19. function isPromise(obj) {
  20. return (
  21. !!obj &&
  22. (typeof obj === 'object' || typeof obj === 'function') &&
  23. typeof obj.then === 'function'
  24. );
  25. }
  26. uni.addInterceptor({
  27. returnValue(res) {
  28. if (!isPromise(res)) {
  29. return res;
  30. }
  31. return new Promise((resolve, reject) => {
  32. res.then(res => {
  33. if (res[0]) {
  34. reject(res[0]);
  35. } else {
  36. resolve(res[1]);
  37. }
  38. });
  39. });
  40. },
  41. });
  42. const app = new Vue({
  43. store,
  44. ...App,
  45. });
  46. // #ifdef H5
  47. RouterMount(app, router, '#app');
  48. // #endif
  49. app.$mount();