vue中的http请

来源:互联网 发布:阿里云系统root 编辑:程序博客网 时间:2024/05/24 07:07
如果vue想发送请求,需要引入: vue-resouce

get:
this.$http.get('aa.txt').then(function(res){
   alert(res.data);
},function(res){
   alert(res.status);
});
给服务发送数据:√
this.$http.get('get.php',{
   a:1,
   b:2
}).then(function(res){
   alert(res.data);
},function(res){
   alert(res.status);
});
post:
this.$http.post('post.php',{
   a:1,
   b:20
},{
   emulateJSON:true
}).then(function(res){
   alert(res.data);
},function(res){
   alert(res.status);
});
jsonp:
this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{
   wd:'a'
},{
   jsonp:'cb' //callback名字,默认名字就是"callback"
}).then(function(res){
   alert(res.data.s);
},function(res){
   alert(res.status);
});
原创粉丝点击