vue-async-data for Vue.js 2.0
Async data loading plugin for Vue.js
Install
- this plugin is written in ES2015, so recommend compile with babel/babel-polyfill.
npm install vue-async-data-2
// use as global plugin;;Vue;
// use as locally mixin;mixins: AsyncDataMixin
Usage
Loading...Error: {{ userNameError }}Hello {{ userName }} !Reload userName
Standard API
this.asyncData: object
specify a function that returns Promise
.
you can also specify a default value.
asyncData: { // return promise return { ; } } userNameDefault: 'unknown' // default value userNameLazy: false // skip run at mount?
this.asyncReload([name])
refresh data.
if name arg is specified, only that field is updated.
thisthis
this.asyncLoading: boolean
global reload flag.
this.asyncError: boolean
global error flag.
Auto Generate Property
this.[name]
if resolve
, set response.
this.[name]Error
if throw reject
, set error message.
this.[name]Loading: boolean
set to true until there response.