vue-h-ajax

Lightweight ajax module for Vue.js 2
552 1
Install
npm install vue-h-ajax
Latest Version:0.1.3
Vue:2
License:MIT
Last Updated:Nov 25, 2017
Links: GitHub  ·  npm
Maintainer: alexander.zonov

vue-h-ajax

npm version npm Build Status

Edge 12+, FF 36+, Chrome 49+, or use translation from ES2105 to ES5

Introduction

vue-h-ajax is the small ajax module for Vue.js. It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include:

  • Lightweight: 3.5kb of sources
  • No dependencies
  • try to parse data as JSON by default
  • withCredentials by default
  • DELETE request with body

Setup

npm install vue-h-ajax

Example

import Vue from 'vue';
import ajax from 'vue-h-ajax';


Vue.use(ajax);


Vue.http.get('/backend/users')
  .then(response => console.log(response.data))
  .catch(response => console.error(response.status));

Vue.http.stop('/backend/users');


const app = new Vue({
  template: '<div class="main"></div>',
  el: '#app',
  created() {
    this.$http.post('/backend/user', {name: 'Bill'}, {'Content-Type': 'application/json'})
      .then(response => {
        console.log(response.data.id);
      })
      .catch(response => console.error(response.status));
  }
});

API

withCredentials
  • type: Boolean. Default true
import Vue from 'vue';
import ajax from 'vue-h-ajax';


Vue.use(ajax);

Vue.http.withCredentials = false;
headers
  • type: Object

Global headers for all requests

import Vue from 'vue';
import ajax from 'vue-h-ajax';


Vue.use(ajax);

Vue.http.headers = {
  'Content-Type': 'application/json'
};
get(url, data, headers), post(...), put(...), delete(...)
  • returns Promise<response>. Response format:
{
  "status": Number,
  "data": Any
}
stop(url)

Abort all current requests matched url

import Vue from 'vue';
import ajax from 'vue-h-ajax';


Vue.use(ajax);


Vue.http.get('/backend/users');
Vue.http.get('/backend/users');
Vue.http.get('/backend/users');

Vue.http.stop('/backend/users');

Related Packages

vue-resource

The HTTP client for Vue.js

4,584,946 9,970
@shaynekasai/v-fetch

A Vue directive to add AJAX to your app without the boilerplate

554
vue-apis

A vue plug-in integrated with axios. Build the API using chain programming and r...

1,066
@frostsw/frostjs

A lightweight JS for basic DOM manipulation and more.

739
stepci

Automated API Testing and Quality Assurance

140,730 1,872

Version History

Version Released Vue License
0.1.3 ^2.5.8 MIT
0.1.2 ^2.1.10 MIT
0.1.1 ^2.1.10 MIT
0.1.0 ^2.1.10 MIT
0.0.4 ^2.1.10 MIT