<template> <div class="tab"> <div :class="{'li-parent':true,light:data.routerName === $store.state.nowTab}" :key="data.path" v-for="data in tabList"> <div class="tab-li" @click="toPath(data.routerName)"> {{data.value}} </div> <i class="iconfont icon-close-b close-btn" v-if="!data.delNo" @click="delPath(data)"></i> </div> </div> </template> <script> export default { name: "tab", data () { return { tabList:this.$store.state.openedTab, } }, mounted:function(){ }, methods:{ toPath:function (name) { this.$router.push({name:name}) }, delPath:function (data) { let i = this.$store.state.openedTab.indexOf(data); this.$store.state.openedTab.splice(i,1); if(data.routerName === this.$store.state.nowTab){ this.$router.push({name:this.$store.state.openedTab[i-1].routerName}) } } } } </script> <style scoped lang="less"> @import "../../util/public"; .tab{ background: #444; padding: 0 5px; position: relative; box-shadow: 0 0 5px @bg-b; .clear-both; .li-parent{ float: left; margin: 5px; user-select:none; transition: all .3s; background: @gold-color; cursor: pointer; font-size: 14px; border-radius: 3px; position: relative; &.light{ background: @gold-color-light; } .close-btn{ position: absolute; top: -4px; right: -4px; transition: all .1s; color: @secondary-font-color; &:hover{ transform: scale(1.2,1.2); color: red; } } .tab-li{ padding: 5px 10px 5px 10px; } } } </style>