项目作者: F-loat

项目描述 :
⚡A small wrapper for integrating superagent to Vuejs
高级语言: JavaScript
项目地址: git://github.com/F-loat/vue-superagent.git
创建时间: 2017-02-02T09:03:10Z
项目社区:https://github.com/F-loat/vue-superagent

开源协议:MIT License

下载


vue-superagent

npm package
npm downloads

A small wrapper for integrating superagent to Vuejs
(reference vue-axios)

How to install:

es6 module:

  1. npm install --save vue-superagent
  2. // or
  3. yarn add vue-superagent

And in your entry file:

  1. import Vue from 'vue'
  2. import VueSuperagent from 'vue-superagent'
  3. Vue.use(VueSuperagent)
  1. // use baseUrl
  2. Vue.use(VueSuperagent, {
  3. baseUrl: 'https://api.douban.com/v2'
  4. })
  5. // *.vue
  6. this.$http
  7. .get('/book/1220562') // => https://api.douban.com/v2/book/1220562
  8. .then(res => console.log(res))
  9. .catch(err => console.log(err));

Usage:

This wrapper bind superagent to Vue or this if you’re using single file component.

You can superagent like this:

  1. Vue.superagent.get(api).then((response) => {
  2. console.log(response.body)
  3. })
  4. this.$superagent.get(api).then((response) => {
  5. console.log(response.body)
  6. })
  7. this.$http.get(api).then((response) => {
  8. console.log(response.body)
  9. })