“Axios is a promise-based HTTP Client for node.js and the browser. It is isomorphic (= it can run in the browser and nodejs with the same codebase). On the server-side it uses the native node.js http module, while on the client (browser) it uses XMLHttpRequests.”
—https://axios-http.com/docs/intro
Axios是一个基于Promise的node.js和浏览器的HTTP客户端。它是同构的(即能够在浏览器和node.js中应用雷同的代码库)。在服务器端,它应用原生的node.js http模块,而在客户端(浏览器)则应用XMLHttpRequests。
对于发送get申请,axios中能够有上面几种形式:
1、axios(config) (倡议应用)
举例:
axios({
method: 'get',
url: '/fund/info',
params: {
fundId: "000001",
type: "bond"
}
});
2、axios(url) || axios(url[, config]) (不倡议应用)
阐明:未指定办法,申请将默认为GET办法。
举例:
axios('/user/info');
axios('/management/doc', {
responseType: "blob",
timeout: 8000,
params: {
id: "abc123"
}
});
3、axios.get(url) || axios.get(url[, config]) (倡议应用)
举例:
axios.get('/fund/basicInfo', {
params: {
fundId: "abc123"
}
});
4、axios.request(config) (不倡议应用)
举例:
axios.request({
method: 'get',
url: "/management/doc"
responseType: "blob",
timeout: 8000,
params: {
id: "abc123"
}
});
以上四种形式都是可行的,倡议在1、3中抉择一种,最好我的项目整体都选用同一种,放弃一致性。
下面各种形式的params最终都会变成url中的query参数
例如:
axios.get('/fund/info, {
params: {
fundId: "000001",
type: "bond"
}
});
最终发送的申请是 /fund/info?fundId=abc123&type=bond
在params中key存在,但value为null或undefined的参数不会在URL中显示。
例如:
axios.get('/fund/info, {
params: {
fundId: "000001",
type: undefined
}
});
最终发送的申请是 /fund/info?fundId=abc123
同步更新到本人的语雀
https://www.yuque.com/dirackeeko/blog/dnlygqwhft5qr1rm
发表回复