Vue-resource

  • vue中的ajax方法库
  • 先附上github的地址
    https://github.com/pagekit/vue-resource
  • 安装 在webpack中需要在package.json中的dependencies中添加"vue-resource":"^1.0.3"
  • 需要在入口文件中依赖和注册
    依赖import VueResource form 'vue-resource'
    注册Vue.use(VueResource)

Elample


{ 
  // GET /someUrl 
  this.$http.get('/someUrl').then((response) => { 
  // success callback
 }, (response) => { 
// error callback
 });
}

在注册了VueResource后,给vue实例this扩展了$http对象,该对象具有ajax方法,在实例代码中get方法返回的对象具有then方法,promess

请求结果作为数据要和vue生命周期中的data结合使用。data可以响应数据的变化

你可能感兴趣的:(Vue-resource)