vue ajax请求

2017-10-11  本文已影响0人  xlayzheng
  1. 应用fetch或axios 获取数据
    axios:http://blog.csdn.net/liaoxiaojuan233/article/details/54176798
    fetch:https://segmentfault.com/a/1190000003810652
     <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

     axios.get(url)

           .then(function (response) {

               console.log(response.data.result);

 

               _that.list=response.data.result;

           })

           .catch(function (error) {

               console.log(error);

           });
  1. https://github.com/pagekit/vue-resource
         <script src="https://cdn.jsdelivr.net/vue.resource/1.0.3/vue-resource.min.js"></script>

         //第二个参数如果返回数据为callback时可以不设置

          this.$http.jsonp(api,{

             jsonp:'cb'//如果接口为不为callback,为cb时,修改此参数,例如https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=php

         }).then(function(data){

             console.log(data.body);

             that.list=data.body.s;

          },function(){

          })
上一篇下一篇

猜你喜欢

热点阅读