1. 安裝vue-resource
npm install vue-resource --save
2.訪問后台地址,在vue中會出現跨域的問題,以下為解決方案
在config下的index.js 中配置proxyTable代理設置
proxyTable: { '/api':{ target:'http://19******:8080', changeOrigin:true,//允許跨域 pathRewrite:{ '/api':'/' } } },
3.地址配置完了,就可以開始訪問后台,獲取數據了
我用的是vue-resource,有多種方式 get,post,json,jsonp,具體使用方法,可以查看官網
this.$http.get('url').then(response => { console.log(response.body); }, response => { console.log(response); });
this.$http.post(('url'),data ,{emulateJSON:false}).then(response => {
console.log(response.body);
}, response => {
console.log(response);
});