axios网络请求
<html>
<head>
<title>
axios网络请求
</title>
</head>
<body>
<input type="button" value="get请求" class="get">
<input type="button" value="post请求" class="post">
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入axios包-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
// get请求
document.querySelector(".get").onclick = function(){
axios.get("https://autumnfish.cn/api/joke/list?num=3")
.then(function(response){
console.log(response)
},function(err){
console.log(err)
})
}
// post请求
document.querySelector(".post").onclick = function(){
axios.post("https://autumnfish.cn/api/user/reg", {
username: "ryan"
}).then(function(response){
console.log(response)
},function(err){
console.log(err)
})
}
</script>