vue-resource
安装
cnpm install vue-resource --save
引入、使用插件
/*引入资源请求插件*/ import VueResource from 'vue-resource' Vue.use(VueResource)
语法:引入vue-resource后,可以基于全局的Vue对象使用http,也可以基于某个Vue实例使用http
// 基于全局Vue对象使用http
Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback);
Vue.http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
// 在一个Vue实例内使用$http
this.$http.get('/someUrl', [options]).then(successCallback, errorCallback);
this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
使用
{
// GET /someUrl
this.$http.get('/someUrl').then(response => {
// get body data
this.someData = response.body;
}, response => {
// error callback
});
}
来源:https://www.cnblogs.com/dxh0535/p/12266119.html