wz_request
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

wz_request

介绍

基于axios封装的请求工具

安装

npm install wz_request

使用说明

Request
import { Request } from 'wz_request';

// 创建一个 request 实例, 自定义拦截器功能
const request = new Request({}, {
  interceptRequest: (config) => {
    config.headers.Authorization = token;
  },
  interceptResponse: (res) => {
    if (res.data.code !== 200) {
      message.error(res.data.msg);
    }
  }
});

// 使用规范化的请求
const res = await request.normalizeGet(url, ops)
if (res.success) {
  // do success
} else {
  // do error
}


// 使用常规请求同axios
request.get(url, ops)
  .then(res => {
    
  })
  .catch(err => {

  })

/wz_request/

    Package Sidebar

    Install

    npm i wz_request

    Weekly Downloads

    2

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    329 kB

    Total Files

    6

    Last publish

    Collaborators

    • z_npm