🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

vue-async-methods

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-async-methods

Vue async methods support

0.0.0
Source
npm
Version published
Weekly downloads
39
39.29%
Maintainers
1
Weekly downloads
 
Created
Source

vue-async-methods Build Status

Vue async methods support

Install

$ npm install vue-async-methods

Usage

import AsyncMethods from 'vue-async-methods'

Vue.use(AsyncMethods)

Now you can define async methods on your vm:

export default {
  asyncMethods: {
    fetchData() {
      return ajax('http://example.com/data.json') //must return a promise
    }
  },
}

And use the following helper variables in your view:

fetchData.isCalled // false until first called
fetchData.isPending
fetchData.isResolved
fetchData.isRejected
fetchData.resolvedWith
fetchData.resolvedWithEmpty //empty means empty object or empty array
fetchData.resolvedWithSomething //opposite of empty
fetchData.rejectedWith //Error object
<button type="button" @click="fetchData">Load data</button>
<div v-if="!fetchData.isCalled">Click button to load data</div>
<div v-if="fetchData.isPending">Loading data...</div>

<div v-if="fetchData.isResolved">
    <div v-if="fetchData.resolvedWithSomething">
        <ul>
            <li v-for="item in fetchData.resolvedWith">
                {{item.name}}
            </li>
        </ul>
    </div>
    <div v-if="fetchData.resolvedWithEmpty">
        Empty list returned
    </div>
</div>

<div v-if="fetchData.isRejected">
    <div v-if="fetchData.rejectedWith">
        Could not load data due to an error. Details: {{fetchData.rejectedWith.message}}
    </div>
</div>

License

MIT © Martin Hansen

FAQs

Package last updated on 02 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts