Created
November 6, 2017 16:39
-
-
Save xcaptain/11d3df3437d5e3864112b620153ddf9b to your computer and use it in GitHub Desktop.
使用typescript + axios异步发送请求
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
async function getBaidu() { | |
return axios.get('http://www.baidu.com'); | |
} | |
async function getBing() { | |
return axios.get('http://www.guazi.com'); | |
} | |
axios.all([getBaidu(), getBing()]) | |
.then(axios.spread(function (bdResp, biResp) { | |
let bdStatus = bdResp.status; | |
let biStatus = biResp.status; | |
console.log('baidu_status code is ', bdStatus, bdResp.data); | |
console.log('bing status code is ', biStatus, biResp.data); | |
})); | |
// tsconfig配置: | |
// target: ["es2017"] | |
// types: ["node"] | |
// 编译命令: tsc typescript_axios_async_request.ts | |
// TODO: 考虑结合RxJS来做事件监听 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment