当前位置:网站首页>Preliminary use of 145 keep alive
Preliminary use of 145 keep alive
2022-07-24 01:58:00 【longfei815】
Switch windows in web pages , Will execute , Component creation and destruction , Switch back to , Re create the component , At this time, the created component is in the initialization state .
for example : If you are registering an account , I accidentally clicked another link , This page jumps to a new window , Click return at this time , The account registration page is recreated , The information you filled in before is gone .
keep-alive Is to help us solve this problem .
keep-alive Do component level caching , The principle is : Do not let components be destroyed and recreated .

Here is the complete code App.vue:
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> |
<router-link to="/user">User</router-link>
</div>
<!-- keep-alive Do component level caching , The principle is : Do not let components be destroyed and recreated -->
<!-- demand : / With cache /about There is no cache
visit / $route.meta.isKeep The value of is true, Two router-view Just show , Yes keep-alive the . So there is cache
visit /about $route.meta.isKeep The value of is false, Two router-view Only show no keep-alive the . So there is no cache
-->
<!-- <keep-alive>
<router-view v-if="$route.meta.isKeep"/>
</keep-alive>
<router-view v-if="!$route.meta.isKeep"/> -->
<!-- :include Specify cached components -->
<keep-alive :include="['Home']">
<router-view />
</keep-alive>
<!-- The values in the array , Is in the component name The value of the property -->
<!-- :exclude Specify components without cache -->
<!-- <keep-alive :exclude="['Home']">
<router-view />
</keep-alive> -->
</div>
</template>
<style lang="less">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
Click to jump to the page , When you return to this page , The data of the page will not change .

边栏推荐
猜你喜欢

ASP.NET CORE写一个缓存Attribute工具

Disadvantages of win11

Exchange 2013 SSL certificate installation document

STM32概念和安装【第一天】

How to use the directory classification function of the new version of easycvr (v2.5.0)?

Upload files to flash file system through Arduino IDE

Hcip day 8 notes

Try to run this command from the system terminal Make sure that you use the correct

Detailed comparison between graphic array and linked list, performance test
![[hiflow] regularly send Tencent cloud SMS sending group](/img/af/40e4a16e4214ae2fc4781e85364a64.png)
[hiflow] regularly send Tencent cloud SMS sending group
随机推荐
[machine learning basics] common operations of Feature Engineering
选址与路径规划问题(Lingo,Matlab实现)
Phantom core is about to close? Is there a future for digital collections?
STM32 concept and installation [day 1]
Precautions for using XXL job
Exchange 2013 SSL certificate installation document
Topological sorting & critical path
[重要通知]星球线上培训第三期来袭!讲解如何在QTYX上构建自己的量化策略!...
Basic network solutions for small and medium-sized hospitals
STM32概念和安装【第一天】
Location and path planning (lingo, matlab implementation)
Vantui, axiso, FAQs and usage:
[untitled]
Spark partition operators partitionby, coalesce, repartition
Notes - record a dynamic datasource please check the setting of primary problem solving
Mysql database UDF authorization learning
Phpcms realizes product multi condition screening function
中小型医院基础网络解决方案
Hcip seventh day notes
利用canvas画图片