# 全局拦截HTTP请求和响应

main.ts中,添加全局请求拦截器, 注册后将会影响到应用内的所有http请求,请根据实际情况选择使用

import { HttpRequest, HttpInterceptorType } from '@fly-vue/core'

...

// 注册全局请求拦截器
HttpRequest.addGlobalInterceptor(HttpInterceptorType.request, (config) => {
  // 对请求进行处理,例如添加请求头
  console.log(config)
  config['headers']['h1'] = 'v1'
  return config
})


// 注册全局响应拦截器
HttpRequest.addGlobalInterceptor(HttpInterceptorType.response, (response) => {
  // 对响应进行处理,例如对数据结果进行统一处理
  console.log(response)
  return response
})

# 重新打包

配置调整完成后,需要重新构建前端工程以及重启后端工程。

顶部