ljc-util

0.9.0 • Public • Published

ljc-util

NPM downloads

Request

简单包装的 Fetch

REQUEST API

  • requestConfig 配置所有默认选项
  • requestHeaders 设置 headers, 支持 object | key-value | function 类型参数
  • send 发送请求
  • getform, postform, get, post, head, del, put 发送请求(这些都是简化的 send)
  • 支持 jsonp
  • 下面为不在$$中的方法
  • create 返回新实例
  • config 同 requestConfig
  • headers 同 requestHeaders
  • prefix 设置请求前缀,可在 config 中设置
  • beforeRequest 请求前 hook
  • afterResponse 响应后 hook
  • contentType 设置 content-type

Usage

import $$ from 'ljc-util';

$$.send('http://httpbin.org/post', {
  method: 'POST',
  data: { name: 'ailjc' },
}).then(resp => {
  console.log(resp.json); // {name: 'ailjc'}
});

// 等价于,使用提供的post方法
$$.post('http://httpbin.org/post', { name: 'ailjc' }).then(resp => {
  console.log(resp.json); // {name: 'ailjc'}
});

Readme

Keywords

none

Package Sidebar

Install

npm i ljc-util

Weekly Downloads

16

Version

0.9.0

License

MIT

Unpacked Size

93.8 kB

Total Files

27

Last publish

Collaborators

  • lujingce