vue-fetch-plugin

2.0.9 • Public • Published

vue-fetch-plugin

fetch plugin for Vuejs project

How to use

npm install --save vue-fetch-plugin

Then configure in your entry file:

import Vue from 'Vue'
import VueFetchPlugin from 'vue-fetch-plugin'
 
Vue.use(VueFetchPlugin, {
  // fetch options
  ...
  credentials: 'include',
  headers: {
    'Content-Type': 'application/json; charset=utf-8',
    'Accept': 'application/json'
  },
  ...
  // request interceptor handler
  reqInterceptor: request => request,
  ...
  // response interceptor handler
  resFilter: response => response,
  resError: error => error
})

Example

Default method in $fetch$get$post:

...
methods: {
  async getTest() {
    const result = await this.$get('url');
    console.log(result);
  },
  async postTest() {
    const result = await this.$post('url', {name: 'kid'});
    console.log(result);
  },
  async fetchTest() {
    const result = await this.$fetch('url', {
        credentials: 'include',
        body: {
          name: 'kid'
        },
        method: 'POST'
      });
    console.log(result);
  }
}
...

Or you can use like this:

import myFetch from 'vue-fetch-plugin';
...
router.beforeEach(async (to, from, next) => {
    ...
    const result1 = await myFetch.post('url', {name: 'kid'});
    const result2 = await myFetch.get('url');
    ...
});
...

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.93latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.93
2.0.81
2.0.70
2.0.60
2.0.50
2.0.40
2.0.31
2.0.20
2.0.10
2.0.00
1.2.50
1.1.50
1.1.40
1.1.31
1.1.21
1.1.10
1.1.01
1.0.90
1.0.81
1.0.71
1.0.60
1.0.50
1.0.4-30
1.0.4-20
1.0.4-10
1.0.40
1.0.30
1.0.20
1.0.1-21
1.0.1-10
1.0.11
1.0.00

Package Sidebar

Install

npm i vue-fetch-plugin

Weekly Downloads

12

Version

2.0.9

License

ISC

Unpacked Size

9.12 kB

Total Files

5

Last publish

Collaborators

  • kid-ding