vue第八课:axios库的使用
axios功能强大的网络请求库。
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
基础使用:
axios.get(地址?key=value&key2=values).then(function(response){},function(err){})
axios.get(地址,{key:value,key2:value2}).then(function(response){},function(err){})
<div id='app'>
<input type="button" value="get请求" @click="getdata">
<p>
{{joke}}
</p>
<input type="button" value="POST请求" @class="post">
</div>
<script>
var app =new Vue({
el:"#app",
data:{
joke:"数据",
},
methods: {
getdata:function(){
var that=this;
axios.get("https://v2.jinrishici.com/info").then(function(response) {
that.joke=response.data.beijingTime
},function(err){})
},
},
})
</script>
本文来自博客园,作者:super_ip,转载请注明原文链接:https://www.cnblogs.com/superip/p/17292769.html