<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="btnPost">发起POST请求</button>
<script src="lib/axios.js"></script>
<script>
document.querySelector('#btnPost').addEventListener('click', async function () {
// 如果调用某个方法的返回值是Promise实例,则前面可以添加await!
// await只能用在被async修饰的方法中
const result = await axios({
method: 'POST',
url: 'https://www.baidu.com/axios/post',
data: {
name: 'zs',
age: 20
}
})
console.log(result)
})
</script>
</body>
</html>
标签:axios,await,调用,result,async,POST
From: https://www.cnblogs.com/yang-young-young/p/17478952.html