// #ifndef VUE3 import Vue from 'vue' import App from './App' // 导入 store 的实例对象 import store from './store/store.js' // 按需导入 $http 对象 import { $http } from '@escook/request-miniprogram' // 在 uni-app 项目中,可以把 $http 挂载到 uni 顶级对象之上,方便全局调用 uni.$http = $http // 封装弹窗的方法 uni.$showMsg = function (title = '数据加载失败!', duration = 1500) { uni.showToast({ title, duration, icon: 'none', }) } // 请求拦截器 $http.beforeRequest = function(options) { uni.showLoading({ title: '数据加载中' }) this.header = { token: uni.getStorageSync('token') } } // 请求的根路径 //$http.baseUrl = 'http://192.168.0.207:8222' $http.baseUrl = 'http://localhost:8222' // 响应拦截器 $http.afterRequest = function(res) { uni.hideLoading() if (!res.data.success) { uni.$showMsg(res.data.message) if (res.data.message === '登录过期,请重新登录') { uni.setStorageSync('token', '') uni.switchTab({ url: '/pages/my/my' }) } } } Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App, // 2. 将 store 挂载到 Vue 实例上 store }) app.$mount() // #endif // #ifdef VUE3 import { createSSRApp } from 'vue' import App from './App.vue' export function createApp() { const app = createSSRApp(App) return { app } } // #endif