在一个页面跳转到另一个页面时,再回来时,页面的数据不变。
例如 点击所在位置,跳转到选择位置页面的时候,回来时,保持跳转前输入的数据不清空。
这就需要用到路由缓存。
首先在路由中配置
{
path: '/publicmoments',
name: 'PublicMoments',
component: PublicMoments,
meta: {
keepAlive:true,//需要开启缓存
},
},
{
path: '/maplocation',
name: 'MapLocation',
component: MapLocation,
meta: {
keepAlive:false,//不需要缓存
},
},
然后在路由出口那里设置
<router-view v-if="!$route.meta.keepAlive" />
<keep-alive>
<router-view v-if="$route.meta.keepAlive" />
</keep-alive>
这样就可以实现部分页面需要缓存数据。