@tripmini/caas-request
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

caas-request


基于 axios 封装的请求工具

/**
 * 发送请求
 * url 请求地址 - 必传
 * method 请求方式 - 默认get 不区分大小写
 * data 请求参数 - 非必传 method为get时会自动拼接至url后面
 * headers 请求头 - 非必传
 * 更多参数 参考 https://axios-http.com/zh/docs/req_config
 */
request({ url: "xxxxx", method: "post", data: {}, headers: {} }).then((res) => {

}),catch(err){

};

/**
 * 注册拦截器
 * request 请求拦截 [发送前回调,发送失败回调-非必传]
 * response 返回拦截 [请求成功回调,请求失败回调-非必传]
 */
request.customizeInterceptor({
  request: [
    conf => {
      console.log("request_1 >>>", conf);
      return conf;
    },
    err => {
      console.log("request_2 >>>", err);
      return Promise.reject(err);
    },
  ],
  response: [
    conf => {
      console.log("response_1 >>>", conf);
      return conf;
    },
    err => {
      console.log("response_2 >>>", err);
      return Promise.reject(err);
    },
  ],
});

Readme

Keywords

none

Package Sidebar

Install

npm i @tripmini/caas-request

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

34 kB

Total Files

6

Last publish

Collaborators

  • wzqhaha
  • wanpan_11
  • channingliu
  • chimyeon
  • gaoneng1850
  • fennghuang