1.1.5-beta.0 • Published 10 months ago

@aplus-frontend/axios v1.1.5-beta.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Repackaged axios to make it easier to send request with axios

NPM Version NPM Downloads NPM License

Quick start

//add -w in you root folder
pnpm install @aplus-frontend/axios -S -w

Methods

post

type: post<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: post method

get

type: get<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: get method

put

type: put<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: put method

delete

type: delete<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: delete method

request

type: request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: request method options

PropsTypedefaultexplanation
configAxiosRequestConfig-AxiosRequestConfig same as axios request config
optionsRequestOptions-RequestOptions

RequestOptions options

PropsTypedefaultexplanation
joinParamsToUrlbooleantrueSplicing request parameters to url
formatDatebooleantrueFormat request parameter time
isTransformResponsebooleantrueWhether to process the request result
isReturnNativeResponsebooleanfalseWhether to return native response headers For example: use this attribute when you need to get the response headers
joinPrefixbooleantrueWhether to join url ,perfix will add to url by default
apiUrlstring-Interface address, use the default apiUrl if you leave it blank
urlPrefixstring-url perfix
errorMessageMode'none'\| 'modal'\|'message'\|'notice'-Error message prompt type
successMessageMode'none'\| 'modal'\|'message'\|'notice'-Success message prompt type
joinTimebooleantrueWhether to add a timestamp,It's will add Timestamp to query params if request type is get
ignoreCancelTokenbooleanfalseIgnore duplicate requests
withTokenbooleantrueWhether to send token in header
retryRequestObject{isOpenRetry: true,count: 5,waitTime: 100}Request retry Strategy
customSuccessMessagestring-Custom success prompt
closeErrorModalbooleanfalseClose error modal

useage example with vue3

You can customize a global hooks method useDefHttp.ts like below:

import { defHttp as _defHttp, VAxios } from '@aplus-frontend/axios'

export function useDefHttp() {
  const globSetting = useGlobSetting()
  const urlPrefix = globSetting.urlPrefix
  const userStore = useUserStoreWithOut()
  const localeStore = useLocaleStore()
  const defHttp = _defHttp({
    apiUrl: globSetting.apiUrl,
    urlPrefix: urlPrefix,
    useMessageHook: useMessage,
    getToken: getToken,
    setToken: userStore.setToken,
    logout: () => {
      if (qiankunWindow.__POWERED_BY_QIANKUN__) {
        qiankunWindow.setGlobalState({
          redirectTo: PageEnum.BASE_LOGIN,
          token: setAuthCache(TOKEN_KEY, undefined),
        })
      } else {
        userStore.logout()
      }
    },
    getLocale: localeStore.getLocale,
  })
  return {
    defHttp,
  }
}

after you can write methods in your project api folder

import { useDefHttp } from '@/hooks/web/useDefHttp';
const { defHttp } = useDefHttp();

//base useage whit post method
export function inventoryInOrderListApi(params: model.InventoryInParams) {
  return defHttp.post<BasicFetchResult<model.InventoryInOrderItem[]>>({
    url: UrlMap.InventoryInOrderList,
    params
  });
}

//Set the return result to blob and close the error pop-up window
export function exportInOrderDetails() {
  return defHttp.post<Blob>(
    {
      url: UrlMap.ExportDetailList,
      responseType: 'blob'
    },
    {
      isTransformResponse: false,
      closeErrorModal: true
    }
  );
}
1.1.5-beta.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.9

11 months ago

1.1.4

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.0.10

10 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.8

11 months ago

1.0.7

12 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.8-beta.1

11 months ago

1.0.7-beta.1

12 months ago

1.0.8-beta.0

11 months ago

1.0.7-beta.0

12 months ago

1.0.0

1 year ago