赞
踩
使用keep-alive
1、在项目的app.vue文件中添加keep-alive
<template>
<div id="app">
<!-- <router-view/> -->
<!--缓存想要缓存的页面,实现后退不刷新-->
<!--加上v-if的判断,可以自定义想要缓存的组件,自定义在router里面-->
<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
</div>
</template>
2、在router文件夹下的index.js文件中,添加mate
{
path: '/',
name: 'index',
component: index,
meta: {
keepAlive: true,
},
},
3、在跳转的新页面中,添加beforeRouteLeave,位置与methods同级
beforeRouteLeave(to,from,next){
to.meta.keepAlive = true
next(0)
},
methods:{}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。