Skip to content

如何获取请求拦截返回的结果呢? #15

@ztongxue

Description

@ztongxue
image

看了文档,发现1.5版本以上支持请求拦截返回

interface BeforeRequestCallbackResult {
    data?: any;
    header?: any;
    method?: Method;
    url?: string;
};

我现在使用的是1.6.2版本,我的写法如下,不知道怎么样才能读取到 header 。

import { Http } from "lwu-request";

interface BeforeRequestCallbackResult {
  data?: any;
  header?: any;
  url?: string;
};

/** 请求前拦截 */
const requestInterceptors = ((object: BeforeRequestCallbackResult)=>{
  console.log(object)
})

/** 响应拦截 */
const responseInterceptors = () => {

}

export const http = new Http({
  baseUrl: {
    // 开发环境域名,此处仅为演示
    dev: import.meta.env.VITE_API_HOST,
    // 生产环境域名,此处仅作为演示
    pro: '',
  },
  // token 携带位置
  takeTokenMethod: "header",
  before: requestInterceptors,
  after: responseInterceptors
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions