vue-resource实现Ajax获取数据

vue-resource是Vue提供的Ajax请求插件

安装

npm install vue-resource

引入

import VueResource from 'vue-resource'
Vue.use(VueResource)

使用

1
2
3
4
5
6
7
// GET /someUrl
this.$http.get('/someUrl').then(response => {
// get body data
this.someData = response.body;
}, response => {
// error callback
});

更新

vue官方推荐使用axio,请查看。

链接