You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67-1Lines changed: 67 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -263,6 +263,29 @@ new Vue({
263
263
}
264
264
```
265
265
266
+
You can trigger re-computation of an async computed property manually, e.g. to re-try if an error occured during evaluation. This should be avoided if you are able to achieve the same result using a watched property.
267
+
268
+
````js
269
+
270
+
new Vue({
271
+
asyncComputed: {
272
+
blogPosts: {
273
+
get () {
274
+
return Vue.http.get('/posts')
275
+
.then(response => response.data)
276
+
},
277
+
}
278
+
},
279
+
methods: {
280
+
refresh() {
281
+
// Triggers an immediate update of blogPosts
282
+
// Will work even if an update is in progress.
283
+
this.$asyncComputed.blogPosts.update();
284
+
}
285
+
}
286
+
}
287
+
````
288
+
266
289
### Conditional Recalculation
267
290
268
291
Using `watch` it is possible to run the computed property again but it will run regardless of the
@@ -323,7 +346,50 @@ new Vue({
323
346
}
324
347
```
325
348
326
-
## Error handling
349
+
## Computation status
350
+
351
+
For each async comptued property, an object is added to `$asyncComputed` that contains information about the current computation state of that object. This object contains the following properties:
352
+
353
+
```js
354
+
{
355
+
// Can be one of updating, success, error
356
+
state:'updating',
357
+
// A boolean that is true while the property is updating.
358
+
updating:true,
359
+
// The property finished updating wihtout errors (the promise was resolved) and the current value is available.
360
+
success:false,
361
+
// The promise was rejected.
362
+
error:false,
363
+
// The raw error/exception with which the promise was rejected.
364
+
exception:null
365
+
}
366
+
```
367
+
368
+
It is meant to be used in your rendering code to display update / error information.
369
+
370
+
````js
371
+
new Vue({
372
+
asyncComputed: {
373
+
posts() {
374
+
return Vue.http.get('/posts')
375
+
.then(response => response.data)
376
+
}
377
+
}
378
+
}
379
+
}
380
+
// This will display a loading message every time the posts are updated:
0 commit comments