axios 并发请求 await async
<!DOCTYPE html><html lang="en"><head><title></title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><script src="
·
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.js"></script>
</head>
<body>
<script>
/** axios 并发请求 **/
function getUserAccount() {
return axios.get('http://192.9.104.65/data/center-data/publish/b592b412bd384fcfb6a29319e4f29d0f');
}
function getUserPermissions() {
return axios.get('http://192.9.104.65/data/center-data/publish/45760d602d6543598427e720db9f9ad8');
}
// axios.all([getUserAccount(), getUserPermissions()])
// .then(axios.spread(function (acct, perms) {
// console.log(acct, perms);
// }));
async function getData() {
const data = await axios.all([getUserAccount(), getUserPermissions()])
console.log('data', data);
}
getData();
</script>
</body>
</html>
更多推荐
已为社区贡献2条内容
所有评论(0)