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>

 

posted @ 2023-04-06 16:29  super_ip  阅读(12)  评论(0编辑  收藏  举报