十六 main.js

100 阅读1分钟
import App from './App'

// #ifndef VUE3
import Vue from 'vue'

Vue.config.productionTip = false
App.mpType = 'app'


//路由表
import {router,RouterMount} from './router.js'  //路径换成自己的
Vue.use(router)

//uView
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

//分享全局混入
import share from '@/mixins/share.js'
Vue.mixin( share );

//工具类
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
Vue.use( VXEUtils,XEUtils);

try {
  function isPromise(obj) {
    return (
      !!obj &&
      (typeof obj === "object" || typeof obj === "function") &&
      typeof obj.then === "function"
    );
  }

  // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  uni.addInterceptor({
    returnValue(res) {
      if (!isPromise(res)) {
        return res;
      }
      return new Promise((resolve, reject) => {
        res.then((res) => {
          if (res[0]) {
            reject(res[0]);
          } else {
            resolve(res[1]);
          }
        });
      });
    },
  });
} catch (error) { }

import store from './store'
const app = new Vue({
	store,
  ...App
})

// 引入请求封装,将app参数传递到配置中
require('./utils/request.js')(app)

//v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
// #ifdef H5
	RouterMount(app,router,'#app')
// #endif

// #ifndef H5
	app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif

// #endif