Vue学习之——ajax和jsonp请求(基于vue-resou

2017-02-15  本文已影响1126人  Lusia_

一、ajax请求

this.$http.get(请求地址,请求参数).then(function(res){  
        //成功的回调函数
        this.$set('resData',res);  
      },function(res){  
         //失败的回调函数
      })   
this.$http.post('/someUrl', [options])
.then(successCallback, errorCallback);

二、jsonp请求

<ul>
  <li v-for="article in articles">
     {{article.title}}
   </li>
</ul>
this.$http.jsonp('https://api.douban.com/v2/movie/top250?count=10',{}, {
        headers: {
        },
        emulateJSON: true
      }).then(function (response) {
        this.articles = response.data["subjects"];
      },function (response) {
        console.log(response);
      });

注意:

Paste_Image.png

后端 response header设置
Access-Control-Allow-Origin: http://xxx.com,允许来自xxx的跨域

上一篇 下一篇

猜你喜欢

热点阅读