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

Vue實(shí)現(xiàn)Tab標(biāo)簽路由效果并用Animate.css做轉(zhuǎn)場(chǎng)動(dòng)畫效果的代碼第2/3頁(yè)

 更新時(shí)間:2020年07月16日 10:31:44   作者:情緒羊  
這篇文章主要介紹了Vue實(shí)現(xiàn)Tab標(biāo)簽路由效果,并用Animate.css做轉(zhuǎn)場(chǎng)動(dòng)畫效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
// 設(shè)置pageList,這里清除其他,也就是保留自己 this.activePage = page.fullPath this.$router.push(this.activePage).catch(e => e) }

緩存控制

這部分邏輯比較簡(jiǎn)單,結(jié)合注釋可以看懂

methods: {
 clearCache (route) {
 const componentName = last(route.matched).components.default.name // last方法來(lái)自lodash,獲取數(shù)組最后一個(gè)元素
 this.dustbin.push(componentName) // 清除
 },
 putCache (route) {
 const componentName = last(route.matched).components.default.name
 if (this.dustbin.includes(componentName)) {
  this.dustbin = this.dustbin.filter(item => item !== componentName) // 從dustbin中刪除當(dāng)前組件名,恢復(fù)其緩存機(jī)制
 }
 }
}

這樣,主要邏輯就做完了,下面簡(jiǎn)單說(shuō)說(shuō)轉(zhuǎn)場(chǎng)動(dòng)畫的實(shí)現(xiàn)

轉(zhuǎn)場(chǎng)動(dòng)畫實(shí)現(xiàn)

轉(zhuǎn)場(chǎng)動(dòng)畫主要是用到 Animate.css 配合Vue的 transition 組件實(shí)現(xiàn),組件完整代碼如下,極其簡(jiǎn)單:

<template>
 <transition :enter-active-class="`animate__animated animate__${name}`">
 <slot />
 </transition>
</template>

<script>
export default {
 name: 'PageToggleTransition',
 props: {
 name: String
 }
}
</script>

具體參考官方文檔 關(guān)于transition組件的說(shuō)明

最后 借鑒自 vue-antd-admin  github.com/1446445040/…

完整代碼

<template>
 <PageLayout>
 <ContextMenu
 :list="menuItems"
 :visible.sync="menuVisible"
 @select="onMenuSelect"
 />
 <!-- 標(biāo)簽部分 -->
 <a-tabs
 type="editable-card"
 :hide-add="true"
 :active-key="activePage"
 @change="changePage"
 @edit="editPage"
 @contextmenu="onContextmenu"
 >
 <a-tab-pane v-for="page in pageList" :key="page.fullPath">
 <template #tab>
  <span :data-key="page.fullPath">
  {{ page.name }}
  </span>
 </template>
 </a-tab-pane>
 </a-tabs>
 <!-- 路由出口 -->
 <PageToggleTransition name="fadeIn">
 <keep-alive :exclude="dustbin">
 <router-view />
 </keep-alive>
 </PageToggleTransition>
 </PageLayout>
</template>

<script>
import { message } from 'ant-design-vue'
import { last } from 'lodash'
import PageLayout from './PageLayout'
import ContextMenu from '../components/common/ContextMenu'
import PageToggleTransition from '../components/transition/PageToggleTransition'

export default {
 name: 'TabLayout',
 components: { PageToggleTransition, ContextMenu, PageLayout },
 data () {
 return {
 pageList: [],
 dustbin: [],
 activePage: '',
 menuVisible: false,
 menuItems: [
 { key: '1', icon: 'arrow-left', text: '關(guān)閉左側(cè)' },
 { key: '2', icon: 'arrow-right', text: '關(guān)閉右側(cè)' },
 { key: '3', icon: 'close', text: '關(guān)閉其它' }
 ]
 }
 },
 watch: {
 $route: {
 handler (route) {
 this.activePage = route.fullPath
 this.putCache(route)
 const index = this.pageList.findIndex(item => item.fullPath === route.fullPath)
 if (index === -1) {
  this.pageList.push(route)
 }
 },
 immediate: true
 }
 },
 methods: {
 changePage (key) {
 this.activePage = key
 this.$router.push(key)
 },
 editPage (key, action) {
 if (action === 'remove') {
 this.remove(key)
 }
 },
 remove (key) {
 if (this.pageList.length <= 1) {
 return message.info('最后一頁(yè)了哦~')
 }
 let curIndex = this.pageList.findIndex(item => item.fullPath === key)
 const { matched } = this.pageList[curIndex]
 const componentName = last(matched).components.default.name
 this.dustbin.push(componentName)
 this.pageList.splice(curIndex, 1)
 // 如果刪除的是當(dāng)前頁(yè)才需要跳轉(zhuǎn)
 if (key === this.activePage) {
 // 判斷向左跳還是向右跳
 curIndex = curIndex >= this.pageList.length ? this.pageList.length - 1 : curIndex
 const page = this.pageList[curIndex]
 this.$router.push(page.fullPath).finally(() => {
  this.dustbin.splice(0) // 重置,否則會(huì)影響到某些組件的緩存
 })
 }
 },
 // 自定義右鍵菜單的關(guān)閉功能
 onContextmenu (e) {
 const key = getTabKey(e.target)
 if (!key) return

 e.preventDefault()
 this.menuVisible = true
 },
 onMenuSelect (key, target) {
 const tabKey = getTabKey(target)
 switch (key) {
 case '1': this.closeLeft(tabKey); break
 case '2': this.closeRight(tabKey); break
 case '3': this.closeOthers(tabKey); break
 default: break
 }
 },
 closeOthers (tabKey) {
 const index = this.pageList.findIndex(item => item.fullPath === tabKey)
 for (const route of this.pageList) {
 if (route.fullPath !== tabKey) {
  this.clearCache(route)
 }
 }
 const page = this.pageList[index]
 this.pageList = 
                            
                            

                        

相關(guān)文章

  • Vue3使用富文本框(wangeditor)的方法總結(jié)

    Vue3使用富文本框(wangeditor)的方法總結(jié)

    項(xiàng)目中用到了富文本,選來(lái)選去選擇了wangeditor,下面這篇文章主要給大家介紹了關(guān)于Vue3使用富文本框(wangeditor)的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • Vue中路由傳參的實(shí)用方式?分享

    Vue中路由傳參的實(shí)用方式?分享

    這篇文章主要為大家詳細(xì)介紹了VUE項(xiàng)目中路由之間的傳值方式,文中的示例代碼講解詳細(xì),涉及到的方法也都是開(kāi)發(fā)時(shí)常用的,希望對(duì)大家有多幫助
    2023-06-06
  • Vue2.x和Vue3.x的雙向綁定原理詳解

    Vue2.x和Vue3.x的雙向綁定原理詳解

    這篇文章主要給大家介紹了關(guān)于Vue2.x和Vue3.x的雙向綁定原理的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Vue+Element樹(shù)形表格實(shí)現(xiàn)拖拽排序示例

    Vue+Element樹(shù)形表格實(shí)現(xiàn)拖拽排序示例

    本文主要介紹了Vue+Element樹(shù)形表格實(shí)現(xiàn)拖拽排序示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Vue 使用中的小技巧

    Vue 使用中的小技巧

    這篇文章主要介紹了Vue 使用中的小技巧,是小編日常開(kāi)發(fā)的時(shí)候用到的小技巧,需要的朋友可以參考下
    2018-04-04
  • Vue3中的動(dòng)態(tài)組件詳解

    Vue3中的動(dòng)態(tài)組件詳解

    本文介紹了Vue3中的動(dòng)態(tài)組件,通過(guò)`<component :is="動(dòng)態(tài)組件名或組件對(duì)象"></component>`來(lái)實(shí)現(xiàn)根據(jù)條件動(dòng)態(tài)渲染不同的組件,此外,還提到了使用`markRaw`和`shallowRef`來(lái)優(yōu)化性能,避免不必要的響應(yīng)式劫持
    2025-02-02
  • 源碼分析Vue3響應(yīng)式核心之effect

    源碼分析Vue3響應(yīng)式核心之effect

    這篇文章主要為大家詳細(xì)介紹了Vue3響應(yīng)式核心之effect的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Vue3有一定的幫助,需要的可以參考一下
    2023-04-04
  • Vue路由參數(shù)的傳遞與獲取方式詳細(xì)介紹

    Vue路由參數(shù)的傳遞與獲取方式詳細(xì)介紹

    顧名思義,vue路由傳參是指嵌套路由時(shí)父路由向子路由傳遞參數(shù),否則操作無(wú)效。傳參方式可以劃分為params傳參和query傳參,params傳參又可以分為url中顯示參數(shù)和不顯示參數(shù)兩種方式。具體區(qū)分和使用后續(xù)分析
    2022-09-09
  • vue中使用elementUI自定義校驗(yàn)及點(diǎn)擊提交不生效問(wèn)題解決辦法

    vue中使用elementUI自定義校驗(yàn)及點(diǎn)擊提交不生效問(wèn)題解決辦法

    我們?cè)陧?xiàng)目中經(jīng)常會(huì)用到ElementUI的表單驗(yàn)證,下面這篇文章主要給大家介紹了關(guān)于vue中使用elementUI自定義校驗(yàn)及點(diǎn)擊提交不生效問(wèn)題解決的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • 詳解vue beforeRouteEnter 異步獲取數(shù)據(jù)給實(shí)例問(wèn)題

    詳解vue beforeRouteEnter 異步獲取數(shù)據(jù)給實(shí)例問(wèn)題

    這篇文章主要介紹了vue beforeRouteEnter 異步獲取數(shù)據(jù)給實(shí)例問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評(píng)論

新干县| 台南县| 团风县| 漾濞| 鄂州市| 祥云县| 临桂县| 天全县| 明溪县| 廊坊市| 周宁县| 宁陕县| 晋江市| 江北区| 林芝县| 大宁县| 合水县| 茂名市| 嘉兴市| 赤壁市| 张家界市| 蒙阴县| 阳高县| 蒙自县| 元江| 隆尧县| 沭阳县| 商水县| 黄大仙区| 松溪县| 余江县| 张掖市| 卫辉市| 苍山县| 枞阳县| 县级市| 南澳县| 获嘉县| 柳林县| 沁阳市| 永济市|