最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue 關(guān)閉當(dāng)前頁(yè)、關(guān)閉當(dāng)前標(biāo)簽tagsView的實(shí)現(xiàn)方法

 更新時(shí)間:2022年08月09日 11:47:38   作者:菜鳥學(xué)編程  
這篇文章主要介紹了Vue 關(guān)閉當(dāng)前頁(yè)、關(guān)閉當(dāng)前標(biāo)簽tagsView,主要有兩種方式,一種是在vue頁(yè)面直接實(shí)現(xiàn),另一種在js文件中寫自定義函數(shù),在vue頁(yè)面中調(diào)用,本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

由于項(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文件中寫自定義函數(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)文章

最新評(píng)論

长泰县| 大港区| 桃园县| 绥阳县| 连江县| 平乡县| 从江县| 舒兰市| 紫金县| 玉田县| 临颍县| 会宁县| 青岛市| 榆林市| 大港区| 岳普湖县| 沙田区| 罗源县| 胶州市| 嫩江县| 钟祥市| 吴川市| 昌宁县| 聂拉木县| 西乌珠穆沁旗| 安吉县| 垦利县| 临沂市| 湘潭市| 台前县| 舞阳县| 柳林县| 鄂伦春自治旗| 射洪县| 叶城县| 芷江| 安新县| 丰都县| 西平县| 阿勒泰市| 台北县|