@@ -214,6 +214,32 @@ export default {
214214}
215215```
216216
217+ #### ` wrapLoading(loader String, func Function, [,force_sync = false]) `
218+
219+ Decorator that wraps function,
220+ will trigger a loading and will end loader after the original function (` func ` argument) is finished.
221+
222+ By default ` wrapLoading ` return async function,
223+ if you want to wrap default sync function pass ` true ` in last argument
224+
225+ _ Example using with async function_
226+
227+ ``` js
228+ methods: {
229+ fetchDataFromApi: wrapLoading (' fetch data' , async function () {
230+ function sleep (ms ) {
231+ return new Promise (resolve => setTimeout (resolve, ms));
232+ }
233+ // do work here
234+ await sleep (3000 );
235+ // simulate some api call
236+ this .fetchResponse = Math .random ()
237+ })
238+ }
239+ ```
240+
241+ See also ` examples/wrap-example `
242+
217243## Using ` v-loading ` Component
218244
219245If you disable ` registerComponents ` option then
@@ -230,7 +256,7 @@ In template, you should wrap your content with `v-loading` component to show loa
230256
231257``` html
232258<v-loading loader =' fetching data' >
233- <template slot =' spinner ' >
259+ <template slot =' loading ' >
234260 This will be shown when "fetching data" loader starts.
235261 </template >
236262
@@ -243,7 +269,7 @@ Better example for a `button` with loading state:
243269``` html
244270<button :disabled =' $vueLoading.isLoading("creating user")' >
245271 <v-loading loader =' creating user' >
246- <template slot =' spinner ' >Creating User...</template >
272+ <template slot =' loading ' >Creating User...</template >
247273 Create User
248274 </v-loading >
249275</button >
@@ -261,7 +287,7 @@ In this example above, the **tab gets data from back-end**, and the **table load
261287<template lang =' pug' >
262288div
263289 v-loading(loader='fetching tabs')
264- template(slot='spinner ')
290+ template(slot='loading ')
265291 b-tabs
266292 template(slot='tabs')
267293 b-nav-item(active disabled)
271297 b-nav-item(v-for='tab in tabs') {{ tab.name }}
272298
273299 v-loading(loader='fetching data')
274- table-gradient-spinner(slot='spinner ')
300+ table-gradient-spinner(slot='loading ')
275301 table
276302 tr(v-for='row in data')
277303 // ...
@@ -309,12 +335,12 @@ You may want to design your own reusable loader for your project. You better cre
309335 </style >
310336```
311337
312- Now you can use your spinner everywhere using ` slot='spinner ' ` attribute:
338+ Now you can use your spinner everywhere using ` slot='loading ' ` attribute:
313339
314340``` html
315341<template lang =" pug" >
316342 v-loading(loader='fetching data')
317- my-spinner(slot='spinner ')
343+ my-spinner(slot='loading ')
318344 div
319345 p My main content after fetching data...
320346</template >
@@ -331,7 +357,7 @@ You need to put them into a `template` tag.
331357
332358``` html
333359<v-loading loader =' fetching data' >
334- <template slot =" spinner " >
360+ <template slot =" loading " >
335361 <v-loading-spinner height =' 30px' width =' 30px' />
336362 </template >
337363
0 commit comments