123456789101112131415161718192021222324252627282930313233 |
- import { config } from "../../common/config";
- import { v4 as uuidV4 } from "uuid";
- /**
- * 请求拦截
- * @param {Object} http
- */
- module.exports = (vm) => {
- uni.$u.http.interceptors.request.use(
- (httpConfig) => {
- // 可使用async await 做异步操作
- // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
- httpConfig.data = httpConfig.data || {};
- if (httpConfig.custom.isIMApi) {
- httpConfig.baseURL = config.getApiUrl();
- }
-
- if (httpConfig.custom.isPgyerApi) {
- httpConfig.baseURL = "https://www.pgyer.com";
- }
- httpConfig.header = {
- ...httpConfig.header,
- operationID: uuidV4(),
- };
- //console.log("qxj httprequest config:"+JSON.stringify(httpConfig));
- // 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
- console.log("qxj httprequest url:"+(httpConfig.baseURL+httpConfig.url)+" \n method:"+httpConfig.method+" header:"+JSON.stringify(httpConfig.header)+" body:"+JSON.stringify(httpConfig.data)+" \n");
- return httpConfig;
- },
- (
- httpConfig, // 可使用async await 做异步操作
- ) => Promise.reject(httpConfig),
- );
- };
|