最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Vue关闭当前页、关闭当前标签tagsView代码实现方法
时间:2022-08-09 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Vue关闭当前页、关闭当前标签tagsView代码实现方法,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
涉及到几个点:
1. 移除VisitedView 和 CachedView 中的当前项
2. 跳转到最后一次访问的标签
主要思路:比对 路由路径 ( this.$route.path)
两种方式:
一、 在vue页面直接实现
closePage() var currentView = this.$store.state.tagsView.visitedViews[0] for (currentView of this.$store.state.tagsView.visitedViews) { if (currentView.path === this.$route.path) { break } } this.$store.dispatch('tagsView/delView', currentView) .then(({ visitedViews }) => { if (currentView.path === this.$route.path) { const latestView = this.$store.state.tagsView.visitedViews.slice(-1)[0] if (latestView) { this.$router.push(latestView) } else { // 如果没有其他标签则跳转到首页 if (currentView.name === '首页') { this.$router.replace({ path: '/redirect' + currentView.fullPath }) } else { this.$router.push('/') } } } })
二、在js文件中写自定义函数,在vue页面中调用
import router from '@/router/routers' // 关闭当前页 关联tagView export function closePage(store, route) { var currentView = store.state.tagsView.visitedViews[0] for (currentView of store.state.tagsView.visitedViews) { if (currentView.path === route.path) { break } } store.dispatch('tagsView/delView', currentView) .then(({ visitedViews }) => { if (currentView.path === route.path) { const latestView = store.state.tagsView.visitedViews.slice(-1)[0] if (latestView) { router.push(latestView) } else { if (currentView.name === '首页') { router.replace({ path: '/redirect' + currentView.fullPath }) } else { router.push('/') } } } }) }
-
下一个: Java多线程实现第三方数据同步代码示例
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24
- SpringBoot热部署设置详解 10-24
- JavaScript二叉搜索树构建操作解析 10-12
- JavaScript二叉树及各种遍历算法讲解 10-12