0.0.16 • Published 5 years ago

vue-fetch-composition v0.0.16

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

vue-fetch-composition

build status npm version npm downloads

Composition function for easy data fetching in Vue using the composition API. Prevents unnecesarry boilerplate code and offers a much more intuative workflow. Inspired by the Nuxt.JS fetch hook.

Installation

Make sure you have the Vue 2 composition API installed.

Using NPM:

npm install vue-fetch-composition --save

Using YARN

yarn add vue-fetch-composition

Using CDN

<script src="https://unpkg.com/vue-fetch-composition@latest/dist/vue-fetch-composition.min.js"></script>

Usage

<template>
    <div>

        <!-- Loading -->
        <template v-if="$fetch.isLoading()">
            Loading...
        </template>

        <!-- Success -->
        <template v-else-if="$fetch.isSuccess()">
            {{ articles }}
        </template>

        <!-- Error -->
        <template v-else-if="$fetch.isError()">
            Oops an error:

            <p>
                {{ $fetch.error }}
            </p>
        </template>
    </div>
</template>

<script>
import { onFetch } from "vue-fetch-composition"

export default {
    setup() {
        const articles = reactive([]);

        const $fetch = onFetch(async () => {
            await fetch("http://api/articles").then(res => res.json());
        });

        return {
            articles,
            $fetch
        }
    }
}
</script>
0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.10

5 years ago

0.0.11

5 years ago

0.0.12

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago