tabsView.vue
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<div class="tabs-wwrapper">
<router-link
class="tab-view"
:to="tag.path"
v-for="tag in getTags"
:key="tag.name"
>
<el-tag
size="small"
closable
:type="getIsActive(tag) ? '' : 'info'"
@close="closeTagView(tag, $event)"
>
{{ tag.name }}
</el-tag>
</router-link>
</div>
</template>
<script>
export default {
computed: {
getTags() {
let tagArr = this.$store.state.app.tagViews;
return tagArr.filter((item) => item.path !== "/article/edit").slice(-6);
},
},
watch: {
$route() {
this.addTagView();
},
},
mounted() {
this.getIsActive();
},
methods: {
getIsActive(tag) {
if (!tag) return;
return tag.path === this.$route.path;
},
closeTagView(tag, e) {
this.$store.dispatch("delTagView", tag);
e.preventDefault();
},
generateRoute() {
if (this.$route.matched[this.$route.matched.length - 1].name) {
return this.$route.matched[this.$route.matched.length - 1];
}
return this.$route.matched[0];
},
addTagView() {
this.$store.dispatch("addTagView", this.generateRoute());
},
},
};
</script>
<style lang="less" scoped>
.tab-view {
margin-left: 10px;
}
</style>