# leng-request **Repository Path**: tb3706666/leng-request ## Basic Information - **Project Name**: leng-request - **Description**: 请求库, 基于 axios npm i leng-request - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-04-11 - **Last Updated**: 2023-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 介绍 请求库, 基于 `axios` ```json "axios": "^0.21.4" "vue": "^3.2.47" "vite": "^4.1.4" ``` --- ## 使用 ### `get(url, params, {config})` [↑](#top) > 不会返回axios的 [**原始数据**](https://axios-http.com/zh/docs/res_schema), 做了data处理 | 参数 | 说明 | | --- | --- | | `url` | '/test' | | `params` | { name: '参数' } | | `config` | 配置: https://axios-http.com/zh/docs/req_config | ```js import { api } from 'admin-request-tools' class car extends api { static testGet(id) { return api.get(`/car/testGet?id=${id}`) } } export default car ``` --- ### `get`, `post` 使用一致 [↑](#top) ```js import { apiRequest } from "admin-request-tools" const testGet = (params) => { return apiRequest.get(`/car/testGet`, params) } ``` ```js import { apiRequest } from "admin-request-tools" const testGet = (params) => { const baseURL = 'https://admin.z-trip.cn/' return apiRequest.get('/car/testGet', params, { baseURL }) } ``` --- ### `instance` [↑](#top) > 等同于 `axios.get`, `axios.post`, 会返回axios的 [**原始数据**](https://axios-http.com/zh/docs/res_schema), 不做data处理 > get ```js import { apiRequest } from "admin-request-tools" apiRequest.instance.get(`/car/testGet?id=${id}`) ``` ```js import { apiRequest } from "admin-request-tools" const config = { headers: { 'Access-Control-Allow-Headers': '*', 'Access-Control-Allow-Origin': '*' }, timeout: 15 * 1000 } apiRequest.instance.get('url', config) ``` > post ```js const params = { name: 'test' } const config = { headers: {'token': 'xxx' } } apiRequest.instance.post(`/car/testGet`, params, config) ``` --- ## 运行 [↑](#top) ```sh pnpm i ``` ```sh # pnpm or yarn yarn start ``` ```sh # pnpm or yarn yarn build ```