vue第八课:axios库的使用

发布时间 2023-04-06 16:32:09作者: super_ip

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>