axios基本使用
axios:功能强大的网络请求库(基于ajax)
axios.get(地址?key=value&key2=values).then(function(response){},function(err){})
sxios.post(地址,{key:value,key:value}).then(function(response){},function(err){})
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<input type="button" value="get请求" class="get">
<input type="button" value="post请求" class="post">
<script>
document.querySelector(".get").onclick = function(){
axios.get("https://autumnfish.cn/api/joke/list0000?num=6")
.then(function(response){
console.log(response);
},function(err){
console.log(err);
})
}
document.querySelector(".post").onclick = function(){
axios.post("https://autumnfish.cn/api/user/reg000",{username:"盐焗西蓝花"})
.then(function(response){
console.log(response);
},function(err){
console.log(err)
})
}
</script>
</body>
axios+vue
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input type="button" value="获取笑话" @click="getJoke">
<p>{{ joke }}</p>
</div>
<script>
var app = new Vue({
el:"#app",
data:{
joke:"很好笑的笑话"
},
methods:{
getJoke:function(){
var that = this;
axios.get("https://autumnfish.cn/api/joke").then(
function(response){
that.joke = response.data;
},function(err){}
)
}
}
})
</script>
</body>