Vue 關(guān)閉當(dāng)前頁(yè)、關(guān)閉當(dāng)前標(biāo)簽tagsView的實(shí)現(xiàn)方法
由于項(xiàng)目使用tagsView,關(guān)閉當(dāng)前頁(yè)面需要通過(guò)關(guān)閉當(dāng)前標(biāo)簽來(lái)實(shí)現(xiàn)
涉及到幾個(gè)點(diǎn):
1. 移除 VisitedView 和 CachedView 中的當(dāng)前項(xiàng)
2. 跳轉(zhuǎn)到最后一次訪問(wèn)的標(biāo)簽
主要思路:比對(duì) 路由路徑 ( this.$route.path)
兩種方式:
一、 在vue頁(yè)面直接實(shí)現(xiàn)
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 { // 如果沒(méi)有其他標(biāo)簽則跳轉(zhuǎn)到首頁(yè) if (currentView.name === '首頁(yè)') { this.$router.replace({ path: '/redirect' + currentView.fullPath }) } else { this.$router.push('/') } } } })
二、在js文件中寫(xiě)自定義函數(shù),在vue頁(yè)面中調(diào)用
import router from '@/router/routers' // 關(guān)閉當(dāng)前頁(yè) 關(guān)聯(lián)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 === '首頁(yè)') { router.replace({ path: '/redirect' + currentView.fullPath }) } else { router.push('/') } } } }) }
到此這篇關(guān)于Vue 關(guān)閉當(dāng)前頁(yè)、關(guān)閉當(dāng)前標(biāo)簽tagsView的文章就介紹到這了,更多相關(guān)Vue 關(guān)閉當(dāng)前頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3?中路由Vue?Router?的使用實(shí)例詳解
vue-router是vue.js官方給出的路由解決方案,能夠輕松的管理SPA項(xiàng)目中組件的切換,這篇文章主要介紹了Vue3?中路由Vue?Router?的使用,需要的朋友可以參考下2023-02-02淺談vuejs實(shí)現(xiàn)數(shù)據(jù)驅(qū)動(dòng)視圖原理
這篇文章主要介紹了淺談vuejs實(shí)現(xiàn)數(shù)據(jù)驅(qū)動(dòng)視圖原理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02vue 請(qǐng)求后臺(tái)數(shù)據(jù)的實(shí)例代碼
本篇文章主要介紹了vue 請(qǐng)求后臺(tái)數(shù)據(jù)的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧、2017-06-06Vue2.0使用嵌套路由實(shí)現(xiàn)頁(yè)面內(nèi)容切換/公用一級(jí)菜單控制頁(yè)面內(nèi)容切換(推薦)
這篇文章主要介紹了Vue2.0使用嵌套路由實(shí)現(xiàn)頁(yè)面內(nèi)容切換/公用一級(jí)菜單控制頁(yè)面內(nèi)容切換,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05element中TimePicker時(shí)間選擇器禁用部分時(shí)間(顯示禁用到分鐘)
這篇文章主要介紹了element中TimePicker時(shí)間選擇器禁用部分時(shí)間(顯示禁用到分鐘),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Vue+WebSocket頁(yè)面實(shí)時(shí)刷新長(zhǎng)連接的實(shí)現(xiàn)
最近vue項(xiàng)目要做數(shù)據(jù)實(shí)時(shí)刷新,數(shù)據(jù)較大,會(huì)出現(xiàn)卡死情況,所以本文主要介紹了頁(yè)面實(shí)時(shí)刷新長(zhǎng)連接,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06vue 動(dòng)態(tài)修改a標(biāo)簽的樣式的方法
這篇文章主要介紹了vue 動(dòng)態(tài)修改a標(biāo)簽的樣式的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01