Skip to content

Commit afe276c

Browse files
committed
add max prop to api for keep-alive
1 parent b59e547 commit afe276c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/v2/api/index.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ type: api
361361
- **Usage:**
362362

363363
Install a Vue.js plugin. If the plugin is an Object, it must expose an `install` method. If it is a function itself, it will be treated as the install method. The install method will be called with Vue as the argument.
364-
364+
365365
This method has to be called before calling `new Vue()`
366366

367367
When this method is called on the same plugin multiple times, the plugin will be installed only once.
@@ -2452,8 +2452,9 @@ Used to denote a `<template>` element as a scoped slot, which is replaced by [`s
24522452
### keep-alive
24532453
24542454
- **Props:**
2455-
- `include` - string or RegExp or Array. Only components matched by this will be cached.
2456-
- `exclude` - string or RegExp or Array. Any component matched by this will not be cached.
2455+
- `include` - string or RegExp or Array. Only components with matching names will be cached.
2456+
- `exclude` - string or RegExp or Array. Any component with a matching name will not be cached.
2457+
- `max` - number. The maximum number of component instances to cache.
24572458
24582459
- **Usage:**
24592460
@@ -2512,7 +2513,19 @@ Used to denote a `<template>` element as a scoped slot, which is replaced by [`s
25122513
25132514
The match is first checked on the component's own `name` option, then its local registration name (the key in the parent's `components` option) if the `name` option is not available. Anonymous components cannot be matched against.
25142515
2515-
<p class="tip">`<keep-alive>` does not work with functional components because they do not have instances to be cached.</p>
2516+
- **`max`**
2517+
2518+
> New in 2.5.0+
2519+
2520+
The maximum number of component instances to cache. Once this number is reached, the cached component instance that was least recently accessed will be destroyed before creating a new instance.
2521+
2522+
``` html
2523+
<keep-alive :max="10">
2524+
<component :is="view"></component>
2525+
</keep-alive>
2526+
```
2527+
2528+
<p class="tip">`<keep-alive>` does not work with functional components because they do not have instances to be cached.</p>
25162529
25172530
- **See also:** [Dynamic Components - keep-alive](../guide/components.html#keep-alive)
25182531

0 commit comments

Comments
 (0)