当前位置:网站首页>Vue returns to the previous page without refreshing the page / Vue caches the page
Vue returns to the previous page without refreshing the page / Vue caches the page
2022-06-30 14:29:00 【Bamboo shrimp】
problem :
vue Within the framework of , When returning to the previous page (this.$router.go(-1)) , By default, the previous page will execute the life cycle again ( Is refreshed ).
The desired effect :
Return to the previous page without refreshing the page .
resolvent :
Cache the page of the previous page , Let it exist , Do not re execute the lifecycle when it is displayed again ;
Using technology :keep-alive(vue Built in components of )
router Routing configuration router/index.js
const routes = [
{
path: '/pageA',
name: 'pageA',
component: () => import('../views/pageA.vue'),
meta: {
title: ' I'm the page A',
keepAlive: false // No need to cache
}
},
{
path: '/pageB',
name: 'pageB',
component: () => import('../views/pageB.vue'),
meta: {
title: ' My page B',
keepAlive: true // Cache required
}
}
]
const router = new VueRouter({
routes
})
Vue.use(VueRouter)
template Template code ( Distribute routing pages ):
<template>
<div id="app">
<!-- Cached pages , cache $route.meta.keepAlive by true The components of -->
<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<!-- Pages not cached , Don't cache $route.meta.keepAlive by false The components of -->
<router-view v-if="!$route.meta.keepAlive"></router-view>
</div>
</template>
explain : By keep-alive Dynamic components of the package ( page ), When component is inactive , Will cache their component instances , Instead of destroying them .
Be careful ( Added hook function ):
There are two more hook functions in the cache page , Triggered when used to show and hide the cached page
// activated Is the hook function after page activation , As soon as you enter the page, it will trigger
activated () {
// Display time
console.log(1)
},
// deactivated The hook function that leaves the page , As soon as you leave the page
deactivated () {
// When not shown
console.log(2)
},
边栏推荐
- QQ 居然被盗了?原因在这......
- 想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
- V3_ Chrome extended Chinese translation document V3 directory
- Begin End use the pit encountered
- Lifting scanning tool
- Shell programming overview
- Tencent two sides: @bean and @component are used on the same class. What happens?
- V3 01_ Welcome
- Pit used by go language array type
- I'd like to ask you, where can I open an account in Foshan? Is it safe to open a mobile account?
猜你喜欢

DefCamp Capture the Flag (D-CTF) 2021-22 web

The first three passes of sqli Labs

Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set

Laravel upload error

Go language mutex lock

"Persistent diseases" that cannot be solved in IM application development

Getting started with shell Basics

Mysql database foundation: stored procedures and functions

Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone

Initial attack and defense world Misc
随机推荐
Error on datetime when importing SQL file from MySQL
Chapter 13 signal (III) - example demonstration
C language & the difference between the address pointed to and the address pointed to by the pointer
Go language for loop multivariable use
ctfshow nodejs
Optimization of unit test efficiency: why test programs? What are the benefits of testing?
数据恢复软件EasyRecovery15下载
Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation
Wuenda 2022 machine learning special course evaluation is coming!
【BUUCTF】 EasySql
[kubernetes series] k8s set mysql8 case insensitive
Small exercise of process and signal
Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit
QQ was stolen? The reason is
深入理解.Net中的线程同步之构造模式(二)内核模式3.内核模式构造物Mutex
Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone
Larave8 JWT API expiration custom error return
Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac