Skip to content

@zzu/axios

基于 axios 实现的 http 请求库。包含了token失效重试、未登录、取消请求、fetchPending、非 200 toast 报错信息、自定义错误处理等功能。

Usage

js
import { axios, type FetchConfig } from '@zzu/axios'

interface deviceInfoIns {
  deviceId: string
}

function fetchDevice(config: FetchConfig = {}): Promise<deviceInfoIns> {
  return axios('xxx', {
    method: 'get',
    ...config
  })
}

const initDevice = async () => {
  const res = await fetchDevice({
    params: {}
  })
  console.log(res)
}

initDevice()

FetchConfig

名称类型默认值说明是否必填
methodenum('get', 'post')-请求方法
urlstring-请求地址
headersRecord<string, string>{}请求头
paramsRecord<string, any>{}查询参数
dataRecord<string, any>{}请求体
toastPendingbooleanfalse是否显示透明遮罩阻止连点
toastErrorbooleanfalse是否显示错误提示
errorMessageHandler(retcode: number | string, message: string) => string | undefined-自定义错误处理