1.Vue的Ajax基本用法
    
     在vue中用Ajax需要用到vue.js和vue-resource.js;
    
     vue-resource.js的下载地址:
     
https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.js
     
    
https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.js
     简单的get请求:
    
     创建一个方法;
    
     方法中调用 this.$http.get()来进行ajax请求;
    
     then()方法做回调函数;
    
     用v-on 将方法绑定到事件;
    
     代码:
    
      <!DOCTYPE html>
     
      <html>
     
      <head>
     
      <meta charset=”utf-8″>
     
      <title>ajax测试</title>
     
      <script src=”vue.js”></script>
     
      <script src=”vue-resource.js”></script>
     
      </head>
     
      <body>
     
      <div id=”app”>
     
      <input type=”button” @click=”get()” value=”点我异步获取数据(Get)”>
     
      </div>
     
      <script type = “text/javascript”>
     
      window.onload = function(){
     
      var vm = new Vue({
     
      el:’#app’,
     
      data:{
     
      msg:’Hello World!’,
     
      },
     
      methods:{
     
      get:function(){
     
      //发送get请求
     
      this.$http.get(‘https://api.auto.ifeng.com/cms/api/revision/wapguide/?page=1&pageCount=10’).then(function(res){
     
      document.write(JSON.stringify(res.body));
     
      },function(){
     
      alert(“请求失败”);
     
      });
     
      }
     
      }
     
      });
     
      }
     
      </script>
     
      </body>
     
      </html>
     
     结果:可以看到请求成功了,返回的是json格式的数据;
    
 
    转载于:https://www.cnblogs.com/ShiningArmor/p/10862885.html
 
