Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-asyncable

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-asyncable

> Async data loading plugin for Vue.js

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
276
increased by70.37%
Maintainers
1
Weekly downloads
 
Created
Source

vue-asyncable

Async data loading plugin for Vue.js

Coverage Status

Install

npm install vue-asyncable --save-dev

Usage

// assuming CommonJS
import { Asyncable } from 'vue-asyncable'

Then, in your component options, provide an asyncData function:

Vue.component('example', {
  mixins: ['Asyncable'],
  data () {
    return {
      orders: [],
      news: []
    }
  },
  asyncData () {
    return {
      orders: this.$axios.$get('api/orders'),
      news: this.$axios.$get('api/news')
    }
  }
})

Object

Property asyncData can be simple object. In this case you don't need to define initial data elements, the module will set it's automatically

Vue.component('example', {
  // ...
  asyncData: {
    orders: axios.$get('api/orders', { user_id: profile.id }),
    news: axios.$get('api/news', { user_id: profile.id })
  }
})

Promise

You can also return a promise that resolves to the data, and return object with promises and siple types

Vue.component('example', {
  // ...
  async asyncData () {
    let profile = await this.$axios.$get('api/profile')
    return {
      profile,
      orders: this.$axios.$get('api/orders', { user_id: profile.id }),
      news: this.$axios.$get('api/news', { user_id: profile.id })
    }
  }
})
Loading State

Your component automatically gets a $loadingAsyncData meta property, which allows you to display a loading state before the data is loaded:

<div v-if="$loadingAsyncData">Loading...</div>
<div v-if="!$loadingAsyncData">Loaded. Put your real content here.</div>

License

MIT

Keywords

FAQs

Package last updated on 15 Jan 2019

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