一、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);
});
注意:
后端 response header设置
Access-Control-Allow-Origin: http://xxx.com
,允许来自xxx的跨域