当前位置:网站首页>TS encapsulation request
TS encapsulation request
2022-06-23 14:24:00 【Qinghua side dish】
import axios, {
AxiosRequestConfig } from 'axios'
import {
Toast } from 'vant'
const instance = axios.create({
baseURL: '',
timeout: 30000,
withCredentials: false,
})
//interceptors by axios Interceptor , effect :
//1. Modify some configuration items of the request header
//2. Add some requested icons to the request process
//3. Add parameters to the request
instance.interceptors.response.use(
response => {
if (response.status === 200 || response.data.data.code === 200 ) {
return response.data
}
return response
},
error => {
const {
response } = error
// console.log("response---:",response)
let message = ' Network error '
if (response && response.data) {
if (response.data.message) {
message = response.data.message
} else if (response.data.data){
message = response.data.data.message
}
}
Toast(message)
return Promise.reject(error)
},
)
/** * ordinary get request , take params Take as the second parameter , And post Unified * @param url * @param params * @param otherConfig * @returns */
export const get = (
url: string,
params?: Record<string, unknown>,
// Allow before sending to server , Modify request data , Can only be used in 'PUT', 'POST' and 'PATCH' These request methods .
// The function in the following array must return a string , or ArrayBuffer, or Stream.
// Pass on to then/catch front , Allow modification of response data
otherConfig?: Omit<AxiosRequestConfig, 'params'>,
) => {
return instance.get(url, {
...(otherConfig || {
}),
params: params || {
},
})
}
export default instance
Use :
import request from './request'
import {
hosts, prefix } from '@/const/hosts'
export const getNearCityByName = (cityName: string) => {
return request.get(`${
hosts.qdfront}/getNearCityByName?cityName=${
encodeURI(cityName)}`)
}
边栏推荐
- 微信小程序之下拉菜单场景
- Instructions for laravel8 Beanstalk
- 【深入理解TcaplusDB技术】一键安装Tmonitor后台
- Intel ® extensions for pytorch* accelerate pytorch
- ICML 2022 𞓜 context integrated transformer based auction design neural network
- MySQL installation
- As a software testing practitioner, do you understand your development direction?
- leetcode:42. Rain water connection
- 图解OneFlow的学习率调整策略
- [digital signal processing] linear time invariant system LTI (judge whether a system is a "non time variant" system | case 3)
猜你喜欢

【深入理解TcaplusDB技术】单据受理之表管理

Gold three silver four, busy job hopping? Don't be careless. Figure out these 12 details so that you won't be fooled~

微信小程序之input调整

面向 PyTorch* 的英特尔 扩展助力加速 PyTorch

The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine
![[deeply understand tcapulusdb technology] tmonitor background one click installation](/img/0a/742503e96a9b51735f5fd3f598b9af.png)
[deeply understand tcapulusdb technology] tmonitor background one click installation

White paper - Intel and Ashling, a well-known risc-v tool provider, strive to expand multi platform risc-v support

Monitor the cache update of Eureka client

如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版

MySQL installation
随机推荐
[digital signal processing] linear time invariant system LTI (judge whether a system is a "non time variant" system | case 2)
大厂架构师:如何画一张大气的业务大图?
IEEE transaction journal revision process record
How to make food nutrition label
Hexiaopeng: if you can go back to starting a business, you won't name the product in your own name
【无标题】
[deeply understand tcapulusdb technology] tmonitor system upgrade
Use xtradiagram Diagramcontrol for drawing and controlling process graphics
[compréhension approfondie de la technologie tcaplusdb] données de construction tcaplusdb
人脸注册,解锁,响应,一网打尽
Add Icon before input of wechat applet
When did the redo log under InnoDB in mysql start to perform check point disk dropping?
微信小程序之flex属性
leetcode:242. Valid Letter ectopic words
[deeply understand tcapulusdb technology] tmonitor background one click installation
微信小程序之input调整
Penetration test - right raising topic
Xmake v2.6.8 发布,编译缓存改进
KS007基于JSP实现人个人博客系统
Intelligent digital signage solution