您现在的位置是:网站首页> 编程资料编程资料
Vue 关闭当前页、关闭当前标签tagsView的实现方法_vue.js_
2023-05-24
333人已围观
简介 Vue 关闭当前页、关闭当前标签tagsView的实现方法_vue.js_
由于项目使用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('/') } } } }) }到此这篇关于Vue 关闭当前页、关闭当前标签tagsView的文章就介绍到这了,更多相关Vue 关闭当前页内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
相关内容
- wasm+js实现文件获取md5示例详解_JavaScript_
- Vue中的@blur事件 当元素失去焦点时所触发的事件问题_vue.js_
- vue实现tagsview多页签导航功能的示例代码_vue.js_
- vue中关于trigger的用法_vue.js_
- JavaScript最少知识原则介绍与体现_javascript技巧_
- JS实现简单网页倒计时器_javascript技巧_
- vue项目 npm run build 打包项目防止浏览器缓存的操作方法_vue.js_
- Node交互式的SFTP上传实现过程剖析_node.js_
- 如何手动销毁Vue中挂载的组件_vue.js_
- vue实现自定义组件挂载原型上_vue.js_
