# vue-api

> Access your models/api/services from components in easy way.

Latest version **0.0.3** (published 2016-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-api
pnpm add vue-api
yarn add vue-api
bun add vue-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-10-23 |
| First published | 2016-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vladimir Metnew |
| Maintainers | metnew |
| Keywords | vue, vuejs, api, plugin, models, services, vue.js, wrapper |

## Links

- npm: https://www.npmjs.com/package/vue-api
- Repository: https://github.com/Metnew/vue-api
- Homepage: https://github.com/Metnew/vue-api#readme
- Issues: https://github.com/Metnew/vue-api/issues
- npm.io page: https://npm.io/package/vue-api

## Recent versions

- 0.0.3 (latest) — 2016-10-23
- 0.0.2 — 2016-10-23
- 0.0.1 — 2016-10-23

## README

# Vue-Api

## Simple wrapper for your models/services in Vue.js

### Access your data models through your Vue.js components without unnecessary file imports.

### Install

```
npm i --save vue-api
```

### Usage

Example repo: <https://github.com/Metnew/vue-api/tree/example>

Add VueApi to your app:

#### index.js

```
import Vue from 'vue';
import VueApi from 'VueApi';
import API from './api.js';
Vue.use(VueApi(api, options)); //setup VueApi
// more about options below
```

Where api.js looks like:

#### api.js

API object have to looks like this:

```
export default const {
    AuthSvc: {
        getUser : async() => {
            let response = await fetch('http://example.com');
            let data = await response.json();
            return data;
        }
    },
    UserSvc: {
        getUserStuff: async() => {
            //your code here
        }
    }
}
```

And now you can access your API through components without imports:

```
export default {
    name: 'Dashboard',
    data() {
        return {};
    },
    created() {
        console.log('Dashboard is created')
    },
    methods: {
        fetchData: async function() {
            let data = await this.$root.api.getUser();
            return data
        }
    }
};
```

### Options

There is only one option:

- **options.forEvery (default: false)** - allows to access API object without **$root** component, like:

  ```
  // component code
      methods: {
          fetchData: async function() {
              let data = await this.api.getUser();
              return data
          }
      }
  // component code
  ```

  **Not recommended.** In this case API property will be mapped to every Vue component of your app.

### Just ~20 lines of code.

### Author

Vladimir Metnew. <https://github.com/Metnew>

### License

MIT

---
_Source: https://npm.io/package/vue-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
