A brief summary of vue keep-alive

A brief summary of vue keep-alive

1. Function

Mainly used to preserve component state or avoid re-rendering.

2. Usage

<keep-alive> When wrapping a dynamic component, inactive component instances are cached instead of being destroyed.

<keep-alive> is an abstract component: it does not render a DOM element itself, nor does it appear in the component's parent chain.

When a component is switched within <keep-alive>, its activated and deactivated lifecycle hook functions will be executed accordingly.

3. Props

include

include - a string or a regular expression. Only components with matching names will be cached.

exclude

exclude - a string or regular expression. Any components with matching names will not be cached.

The include and exclude props allow components to be conditionally cached. Both can be expressed as a comma-delimited string, a regular expression, or an array:

<!-- Comma separated string -->
<keep-alive include="a,b">
 <component :is="view"></component>
</keep-alive>

<!-- Regular expression (using `v-bind`) -->
<keep-alive :include="/a|b/">
 <component :is="view"></component>
</keep-alive>

<!-- Array (using `v-bind`) -->
<keep-alive :include="['a', 'b']">
 <component :is="view"></component>
</keep-alive>

Matching is first checked against the component's own name option, or if that is not available, against its locally registered name (the value of the parent component's components option key). Anonymous components cannot be matched.

max

max : a number. The maximum number of component instances that can be cached.

Once this number is reached, the cached component instance that has not been accessed in the longest time will be destroyed before a new instance is created.

<keep-alive :max="10">
 <component :is="view"></component>
</keep-alive>

The above is a brief analysis of the details of keep-alive in vue. For more information about keep-alive in vue, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Keep-alive multi-level routing cache problem in Vue
  • Example of usage of keep-alive component in Vue
  • In-depth understanding of keep-alive components in Vue
  • Two ways to apply keep-alive in Vue
  • Detailed explanation of keep-alive in Vue

<<:  MySQL implements increasing or decreasing the specified time interval for all times in the current data table (recommended)

>>:  CentOS 7 configuration Tomcat9+MySQL solution

Recommend

CSS uses the autoflow attribute to achieve seat selection effect

1. Autoflow attribute, if the length and width of...

JavaScript implements random generation of verification code and verification

This article shares the specific code of JavaScri...

How to optimize a website to increase access speed update

Recently, the company has begun to evaluate all s...

Reasons and solutions for not being able to detect array changes in Vue2

Table of contents Workaround Why can't I moni...

Process parsing of reserved word instructions in Dockerfile

Table of contents 1. What is Dockerfile? 2. Analy...

jQuery uses the canvas tag to draw the verification code

The <canvas> element is designed for client...

An article explains Tomcat's class loading mechanism

Table of contents - Preface - - JVM Class Loader ...

Vue uses plug-ins to cut pictures in proportion

This article shares the specific code of Vue usin...

Use href in html to pop up a file download dialog box when clicking a link

I learned a new trick today. I didn’t know it befo...

Code analysis of user variables in mysql query statements

In the previous article, we introduced the MySQL ...

Detailed explanation of grep and egrep commands in Linux

rep / egrep Syntax: grep [-cinvABC] 'word'...

How to set static IP in CentOS7 on VirtualBox6 and what to note

Install CentOS 7 after installing VirtualBox. I w...

Zabbix monitoring solution - the latest official version 4.4 [recommended]

Zabbix 2019/10/12 Chenxin refer to https://www.za...

How to modify the root password of mysql in docker

The first step is to create a mysql container doc...

jQuery achieves the effect of advertisement scrolling up and down

This article shares the specific code of jQuery t...