Vue路由开启keep-alive缓存页面

2019-12-14 21:02:45

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();
   }


  • 2020-12-01 16:43:37

    fieldset标签做输入框

    比如 vuetify中的 input组件,就用到了fieldset做边框, 这个时候我们想改边框,却找不到border,因为fieldset是靠color来修改边框颜色的。

  • 2020-12-01 17:25:39

    axios并发操作

    很多时候,我们需要同时向后端进行多个请求,当所有请求都返回数据后,再进行一些操作。

  • 2020-12-02 14:45:35

    Remote-SSH使用教程 VSCode

    微软开发了一个VSCode的插件Remote-SSH,可以说是目前比较完美的解决了在windows下开发linux程序的问题。

  • 2020-12-02 22:56:09

    android设置禁止横屏失效崩溃

    误区,其实这两个代码都不是禁止横屏的,可以说根本没有禁止横屏的代码,这两个代码是设置竖屏的。 并且安卓先检测xml代码,如果是竖屏就直接展示竖屏的,但是如果java代码中设置的横屏,他会先展示竖屏咱展示横屏的 。

  • 2020-12-03 10:43:18

    xshell 连接 wsl

    装上 ubuntu on windows 后,默认要先打开 cmd, 再运行 bash 进入 ubuntu 的 shell。 但是这个shell很难看,配色不好就算了,还存在各种复制粘贴麻烦、默认没进入 home 目录、各种报警声等问题。所以尝试用 xshell 登陆 ubuntu