1.0.1 • Published 4 years ago

@lichao.franklee/lcajax v1.0.1

Weekly downloads
2
License
ISC
Repository
-
Last release
4 years ago
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
}

待实现想法:

1.0.1

4 years ago

1.0.0

4 years ago