Socket
Book a DemoInstallSign in
Socket

@lichao.franklee/lcajax

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lichao.franklee/lcajax

```js new Ajax(options) ```

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source
new Ajax(options)

其中,options的配置项如下:

{
  rest
  // TODO: 传递请求库的对象,自动识别对象,消除上面的requestLib参数
  requestInstance
  defaultOptions // 请求的默认配置
  extension // ajax实例扩展,对象,可选
  isProduction // 是不是正式环境,用以开启或关闭某些功能,boolean/() => bool
  // 请求拦截器处理函数,(config) => config,可选,不要使用箭头函数,函数内this指向ajax实例
  requestInterceptor
  // 响应成功拦截器处理函数,response => response, 可选,不要使用箭头函数,函数内this指向ajax实例
  responseOkInterceptor
  // 响应请求错误的拦截器,即status不等于304且不在[200, 300),error => any,可选
  // 不要使用箭头函数,函数内this强制指向ajax实例
  responseErrorInterceptor
  responseNotOkHandler // 请求正常返回,但后端判断请求出错,response => any
  schema // jsonschema,结构和rest保持一致,可选
  handleRequestDataInvalid // 响应数据校验未通过时的处理函数, (res, validInfo) => any
  handleResponseDataInvalid // 请求数据校验未通过时的处理函数, (res, validInfo) => any
}

其中,rest

{
  moduleName: {
    requestFunction: [method, url, params],
    // ...
  },
  // ...
}

其中,params可选参数:

{
  isReturnRes // Boolean,true表示直接返回response,false表示返回response.data
  baseUrl // 请求路径前缀,拼接在url之前,构成一个完整的请求路径
  cache // Boolean,该请求是否开启缓存,可选,默认false
}

待实现想法:

Keywords

ajax

FAQs

Package last updated on 21 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts