代码包含 axios 的基础常用功能写法与配置项,适合快速入门
const ins = axios.create({
baseURL: 'https://www.showdoc.com.cn/server/api/user/login',
timeout: 1000,
})
ins.interceptors.request.use(config => {
console.log('send the request')
return config
})
ins.interceptors.response.use(config => {
console.log('send the response')
return config
})
const res1 = await ins.get('')
.then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
const res2 = await ins.post('', {
form: [
{
name: "admin",
pwd: "123456",
},
{
name: "admin",
pwd: "123456",
}
]
})
console.log(res2.data)
看到这里,点个赞呗