<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
rel="stylesheet"
href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css"
/>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
</head>
<body>
<div>
<h2 class="page-header">基本使用</h2>
<button class="btn btn-primary">發送GET請求</button>
<button class="btn btn-warning">發送POST請求</button>
</div>
<script>
const btns = document.querySelectorAll("button");
const duixiang=axios.create({
baseURL:'https://api.apiopen.top',
timeout:2000
})
//方法一
// duixiang({
// url:'/getJoke'
// }).then(response=>{
// console.log(response);
// })
//方法二 借助封裝好的方法
duixiang.get('/getJoke').then(response=>{
console.log(response);
})
</script>
</body>
</html>