美文网首页
Vue-resource

Vue-resource

作者: 奈何明月照沟渠 | 来源:发表于2017-01-13 18:54 被阅读0次
  • 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

      本文链接:https://www.haomeiwen.com/subject/ciysbttx.html