1.2.0 • Published 7 years ago

vue-superagent v1.2.0

Weekly downloads
41
License
MIT
Repository
github
Last release
7 years ago

vue-superagent

reference vue-axios

A small wrapper for integrating superagent to Vuejs

NPM

How to install:

es6 module:

npm install --save vue-superagent
// or
yarn add vue-superagent

And in your entry file:

import Vue from 'vue'
import VueSuperagent from 'vue-superagent'

Vue.use(VueSuperagent)
// use baseUrl
Vue.use(VueSuperagent, {
  baseUrl: 'https://api.douban.com/v2'
})

// *.vue
this.$http
  .get('/book/1220562') // => https://api.douban.com/v2/book/1220562
  .then(res => console.log(res))
  .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:

Vue.superagent.get(api).then((response) => {
  console.log(response.body)
})

this.$superagent.get(api).then((response) => {
  console.log(response.body)
})

this.$http.get(api).then((response) => {
  console.log(response.body)
})