Util to merge asyncData methods on route pages in nuxt framework.
Install
npm i nuxt-merge-asyncdata -save
Usage
... // asynchronous
API
nmerge({...})
Default method will collect all asyncData methods and run them in parallel (asynchronous). Results will be merged together with respect to hierarchy.
let base = asyncData: async { console await // some delay console return value: 1 } mixins: base asyncData: async { console return value: 2 } { console }
Result
> asyncData in base: start
> asyncData in component
> asyncData in base: end
> value is 2
nmerge.sync({...})
sync
method differs in a way that it will run asyncData methods synchronously, it will also continuously merge results and pass them to next method in context field asyncDataResult
let base = asyncData: async { console await // some delay console return value: 1 }
Result
> asyncData in base: start
> asyncData in base: end
> asyncData in component, base result is: { value: 1 }
> value is 2
nmerge.manual({...}) nmerge.controlled({...})
These methods will just flatten out mixins hierarchy removing duplicates and filter out mixins without asyncData methods, resulted array will be passed to component asyncData method in mixins
field.
Difference between manual
and controlled
is that if asyncData is not present on passed component then controlled
will assume that invocation of base asyncData methods is desired and will fallback on default (asynchronous) method whether manual
will do nothing.
let core = name: 'core' asyncData: async { ... } let base = name: 'base' mixins: core asyncData: async { ... } let comp2 = name: 'comp2' mixins: core asyncData: async { ... }