2.0.9 • Published 4 years ago

vue-fetch-plugin v2.0.9

Weekly downloads
4
License
ISC
Repository
-
Last release
4 years ago

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');
    ...
});
...
2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.5

4 years ago

2.0.6

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

5 years ago

1.2.5

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4-3

6 years ago

1.0.4-2

6 years ago

1.0.4-1

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1-2

6 years ago

1.0.1-1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago