Fetch

Banshee component for handling APIs.

Basic Usage

<template>
  <div id="app">
    <banshee-fetch url="https://jsonplaceholder.typicode.com/posts/1" mode="cors">
      <div slot-scope="{ loading, response }">
        <div v-if="loading">Loading...</div>
        <div v-if="response && !loading">
          <h2>{{ response.title }}</h2>
          <p>{{ response.body }}</p>
        </div>
      </div>
    </banshee-fetch>
  </div>
</template>

The <banshee-fetch> component is an abstraction over the browser's own fetch API. Instead of using methods, mixins, and lifecycle hooks to manage API data you can create services via the <banshee-fetch> component.

Fetch

Attributes & Props

The banshee-fetch component takes much of the same options that the Browser fetch does since it's built directly on top of it.

NameRequiredTypeDefaultDescription
bodyfalseObject{}Any body that you want to add to your request.
cachefalseString'default'The cache mode you want to use for the request: default, no-store, reload, no-cache, force-cache, or only-if-cached.
credentialsfalseString'omit'The request credentials you want to use for the request: omit, same-origin, or include.
headersfalseObject{}Any headers you want to add to your request, contained within a Headers object.
lazyfalseBooleanfalseWhether the component should immediately fetch the data or not.
methodfalseString'GET'The request method.
modefalseString'same-origin'The mode you want to use for the request, e.g., cors, no-cors, or same-origin.
redirectfalseString'follow'The redirect mode to use: follow (automatically follow redirects), error (abort with an error if a redirect occurs), or manual (handle redirects manually).
referrerfalseString'client'A USVString specifying no-referrer, client, or a URL.
urltrueStringN/AThe API url.

Events

EventParametersDescription
onDataReceived(data)occurs on successful ajax call, returns response data from ajax call
onError(error)occurs when ajax call results in error, returns ajax response error

Scoped Slots

PropertyDescription
errorerror object if the ajax call caught an error
loadingboolean, whether or not we are still waiting for response from server
responseresponse data from server from successful fetch
fetchmethod, if lazy prop is present utilize this to trigger fetch
Last Updated: 6/13/2018, 10:57:53 PM