Prototype

$api

The $api prototype is a wrapper for [axios](https://github.com/mzabriskie/axios\ and you can use it easily anywhere in you application, it accepts the same options that axios does, just pass the option object when using on Vue.use(VueRest, { axiosOptions: { baseUrl: 'http://localhost' } }).

Example:

export default {
  ...
  methods: {
    loadMyObject() {
      this.$api.get('http://myapi.com/1/').then((response) => {
        this.myObj = response.data;
        ...
      }).catch((err) => {
        ...
      });
    },
    // NOTE: You can use it with ECMAScript2016 async/await
    async saveMyObject() {
      const response = await this.$api.post('http://myapi.com', this.myObj);
      this.myObj = response.data;
    },
  },
  ...
};

results matching ""

    No results matching ""