Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
decreased by-6.15%
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.execute // executes the method
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.execute">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 18 Sep 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc