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

Detailed analysis and testing of SSD performance issues in MySQL servers

【question】 We have an HP server. When the SSD wri...

How to use webSocket to update real-time weather in Vue

Table of contents Preface About webSocket operati...

Pure CSS to achieve input box placeholder animation and input verification

For more exciting content, please visit https://g...

How to query duplicate data in mysql table

INSERT INTO hk_test(username, passwd) VALUES (...

Explanation of the working principle and usage of redux

Table of contents 1. What is redux? 2. The princi...

Join operation in Mysql

Types of joins 1. Inner join: The fields in the t...

Solve the problem that ifconfig and addr cannot see the IP address in Linux

1. Install the Linux system on the virtual machin...

Use personalized search engines to find the personalized information you need

Many people now live on the Internet, and searchin...

Installation, activation and configuration of ModSecurity under Apache

ModSecurity is a powerful packet filtering tool t...

Detailed steps for installing JDK and Tomcat on Linux cloud server (recommended)

Download and install JDK Step 1: First download t...

Detailed explanation of the use of title tags and paragraph tags in XHTML

XHTML Headings Overview When we write Word docume...

Detailed explanation of the steps to build a Vue project with Vue-cli

First you need to install Vue-cli: npm install -g...

Docker uses busybox to create a base image

The first line of a Docker image starts with an i...