vue 通过 vue-resource 调用 后台接口

import Vue from 'vue'
import VueResource from 'vue-resource'
Vue.use(VueResource);
function HTTP(){
this.Vue=Vue;
//域名
this.baseurl=function(num){
var strurl="";
switch(num)
{
case 1:{strurl="http://localhost:37377";break;}
case 2:{strurl="http://localhost:37377";break;}
default:{strurl="http://localhost:37377";break;}
}
return strurl;
},
//get 提交
this.Get=function(url,param,type){
return this.Vue.http.get(this.baseurl(type)+url,{params:param});
},
//post 提交
this.Post=function(url,param,type)
{
return this.Vue.http.post(this.baseurl(type)+url,param,{emulateJSON:true});

}

}
var http=new HTTP();
export default http;
原文地址:https://www.cnblogs.com/gfbppy/p/10966524.html