mode:hash模式下:
HTML部分:
1 2 3 4 5 6 7 8 | <template> <div id= "app" > <keep-alive> <!--使用keep-alive会将页面缓存--> <router-view v- if = "$route.meta.keepAlive" ></router-view> </keep-alive> <router-view v- if = "!$route.meta.keepAlive" ></router-view> </div> </template> |
路由部分:
1 2 3 4 5 6 7 8 | { path: '/home' , name: '首页' , menuShow: true , iconCls: 'home_light.svg' , component: Home, meta:{keepAlive: true } }<br>页面部分: |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //缓存页面 beforeRouteLeave(to, from, next) { // 设置下一个路由的 meta to.meta.keepAlive = true ; // B 跳转到 A 时,让 A 缓存,即不刷新(代码写在B页面) next(); } //不缓存页面 beforeRouteLeave(to, from, next) { // 设置下一个路由的 meta to.meta.keepAlive = false ; // B 跳转到 A 时,让 A 不缓存,即刷新(代码写在B页面) next(); } |