vue中和后台交互,首先要引用vue-resource.js
<!-- 引入vue-resource插件-->
<script src="../js/vueJs/vue-resource.js"></script>
vue中get请求
function getRequest(url, params) {
return new Promise((resolve, reject) => {
Vue.$http.get(
url,
{
params: params
},
{emulateJSON: true}
)
.then((res) => {
resolve(res);
})
.catch((res) => {
reject(res);
});
});
}
vue中post请求
function postRequest(url, params) {
return new Promise((resolve, reject) => {
Vue.$http.post(
url,
{
params
},
{emulateJSON: true}
)
.then((res) => {
resolve(res.body);
})
.catch((res) => {
reject(res.body);
});
});
}