Vue实现页面跳转上一页面不刷新
step1:配置路由缓存
export default new Router({
routes: [
{
path: '/hello',
name: 'hello',
meta: {
keepAlive: true // 需要缓存
}
}
],
})
step2:配置App.vue文件中的的<router-view/>
<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
step3:使用this.$router.back()返回
按钮的返回事件 this.$router.go(-1)换成this.$router.back()