Vue实现Tab标签路由效果并用Animate.css做转场动画效果的代码
更新时间:2020年07月16日 10:31:44 作者:情绪羊
这篇文章主要介绍了Vue实现Tab标签路由效果,并用Animate.css做转场动画效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
this.activePage = page.fullPath this.$router.push(this.activePage).catch(e => e) }, closeLeft (tabKey) { const index = this.pageList.findIndex(item => item.fullPath === tabKey) this.pageList.forEach((route, i) => { if (i < index) { this.clearCache(route) } }) const restPages = this.pageList.slice(index) this.pageList = restPages // 判断当前activePage是否在将要删除的页面中 const curActivePage = restPages.find(item => item.fullPath === this.activePage) if (!curActivePage) { this.activePage = restPages[0].fullPath this.$router.push(this.activePage).catch(e => e) } }, closeRight (tabKey) { const index = this.pageList.findIndex(item => item.fullPath === tabKey) this.pageList.forEach((route, i) => { if (i > index) { this.clearCache(route) } }) const restPages = this.pageList.slice(0, index + 1) this.pageList = restPages // 判断当前activePage是否在将要删除的页面中 const curActivePage = restPages.find(item => item.fullPath === this.activePage) if (!curActivePage) { this.activePage = last(restPages).fullPath this.$router.push(this.activePage).catch(e => e) } }, /** * 缓存控制 */ clearCache (route) { const componentName = last(route.matched).components.default.name 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) } } }}/** * 获取Tab标签下dom节点中自定义的数据,递归向下查找最多3层(观察Tab组件渲染后的DOM得出) * 该方式属于hack手段,不得已为之 * @param{HTMLElement} target event.target * @param depth 深度 */function getTabKey (target, depth = 0) { if (depth > 2 || !target) { return null } return target.dataset.key || getTabKey(target.firstElementChild, ++depth)}</script>
总结
到此这篇关于Vue实现Tab标签路由效果,并用Animate.css做转场动画的文章就介绍到这了,更多相关Vue实现Tab标签路由内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!


最新评论