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ān)閉當(dāng)前標(biāo)簽來實(shí)現(xiàn)
涉及到幾個(gè)點(diǎn):
1. 移除 VisitedView 和 CachedView 中的當(dāng)前項(xiàng)
2. 跳轉(zhuǎ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 {
// 如果沒有其他標(biāo)簽則跳轉(zhuǎn)到首頁(yè)
if (currentView.name === '首頁(yè)') {
this.$router.replace({ path: '/redirect' + currentView.fullPath })
} else {
this.$router.push('/')
}
}
}
})二、在js文件中寫自定義函數(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)文章
使用vue-cli初始化項(xiàng)目時(shí)運(yùn)行‘npm run dev’報(bào)錯(cuò)及解決
這篇文章主要介紹了使用vue-cli初始化項(xiàng)目時(shí)運(yùn)行‘npm run dev’報(bào)錯(cuò)及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Elementui?el-input輸入框校驗(yàn)及表單校驗(yàn)實(shí)例代碼
輸入框是使用非常多的元素,用來輸入用戶名、密碼等等信息,Element提供了功能和樣式豐富的輸入框,下面這篇文章主要給大家介紹了關(guān)于Elementui?el-input輸入框校驗(yàn)及表單校驗(yàn)的相關(guān)資料,需要的朋友可以參考下2023-06-06
vue?router如何實(shí)現(xiàn)tab切換
這篇文章主要介紹了vue?router如何實(shí)現(xiàn)tab切換,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue通過vue-router實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的全過程
這篇文章主要介紹了Vue通過vue-router實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的操作步驟,文中有詳細(xì)的代碼示例和圖文供大家參考,對(duì)大家的學(xué)習(xí)或工作有一定的幫助,感興趣的朋友可以參考下2024-04-04
Vue項(xiàng)目中使用setTimeout存在的潛在問題及解決
這篇文章主要介紹了Vue項(xiàng)目中使用setTimeout存在的潛在問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
SpringBoot+Vue前后端分離,使用SpringSecurity完美處理權(quán)限問題的解決方法
這篇文章主要介紹了SpringBoot+Vue前后端分離,使用SpringSecurity完美處理權(quán)限問題,需要的朋友可以參考下2018-01-01
Vue聲明式導(dǎo)航與編程式導(dǎo)航示例分析講解
這篇文章主要介紹了Vue中聲明式導(dǎo)航與編程式導(dǎo)航,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-11-11
VUE.CLI4.0配置多頁(yè)面入口的實(shí)現(xiàn)
這篇文章主要介紹了VUE.CLI4.0配置多頁(yè)面入口的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

