main.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. Vue.config.productionTip = false
  5. App.mpType = 'app'
  6. try {
  7. function isPromise(obj) {
  8. return (
  9. !!obj &&
  10. (typeof obj === "object" || typeof obj === "function") &&
  11. typeof obj.then === "function"
  12. );
  13. }
  14. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  15. uni.addInterceptor({
  16. returnValue(res) {
  17. if (!isPromise(res)) {
  18. return res;
  19. }
  20. return new Promise((resolve, reject) => {
  21. res.then((res) => {
  22. if (res[0]) {
  23. reject(res[0]);
  24. } else {
  25. resolve(res[1]);
  26. }
  27. });
  28. });
  29. },
  30. });
  31. } catch (error) { }
  32. //import Permission from './directive/permission.js'
  33. //Vue.use(Permission)
  34. import btnPermission from './directive/permission.js';
  35. Vue.prototype.$has = btnPermission;
  36. import api from '@/http/index.js'
  37. // 全局挂载后使用
  38. Vue.prototype.$api = api
  39. // 引入全局uView
  40. import uView from '@/uni_modules/uview-ui'
  41. Vue.use(uView)
  42. uni.$u.config.unit = 'rpx'
  43. const app = new Vue({
  44. ...App
  45. })
  46. app.$mount()
  47. // #endif
  48. // #ifdef VUE3
  49. import { createSSRApp } from 'vue'
  50. export function createApp() {
  51. const app = createSSRApp(App)
  52. return {
  53. app
  54. }
  55. }
  56. // #endif