How to use keep-alive in vue2.0
This article mainly introduces how to use keep-alive in vue2.0. It is very detailed and has a certain reference value. Friends who are interested must finish it!
1. Basic usage
Vue2.0 provides a keep-alive component for caching components to avoid loading the corresponding components multiple times and reduce performance consumption
Sometimes you may need to cache all the pages of the entire site, and the request is usually triggered as soon as the page is entered.
In the case of keep-alive
Caching can be implemented by writing the first trigger request in the created hook function
For example, the list page, if you go to the details page, it is still on the original page.
two。 Cache part of the page or component
(1) using router. Meta attribute
/ / this is the most commonly used method at present.
Router Settin
... Routes: [{path:'/', redirect:'/ index', component: Index, meta: {keepAlive: true}}, {path:'/ common', component: TestParent, children: [{path:'/ test2', component: Test2, meta: {keepAlive: true}}]}. / / indicates that both index and test2 use keep-alive
(2)。 Use the new property inlcude/exclude
After 2.1.0, two attributes of include/exclude are provided to cache the corresponding components.
/ / where aformab is the name of the component
Note: this method knows the name of the component in advance.
(3) dynamic judgment
IncludedComponents can be set dynamically.
The above is all the contents of the article "how to use keep-alive in vue2.0". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!