-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMenuButton.vue
47 lines (42 loc) · 1.13 KB
/
MenuButton.vue
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
<template>
<div class="flex justify-center">
<Button
v-bind="$attrs"
:preset="buttonPreset"
:to="to"
v-on="$listeners"
>
<template
v-for="(_, slot) of $scopedSlots"
#[slot]
>
<slot :name="slot" />
</template>
</Button>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
// eslint-disable-next-line import/no-extraneous-dependencies
import { Location } from 'vue-router'
enum Router {
index = 'index___en',
search = 'search-keyword___en'
}
@Component
export default class MenuButton extends Vue {
@Prop({ default: null }) readonly to: Location | null | undefined
get isSelected() {
if (!this.to) return false
const toNameWithoutLocale = this.to?.name?.split('___')[0] || '';
const routeNameWithoutLocale = this.$route.name?.split('___')[0] || '';
return (
routeNameWithoutLocale.startsWith(toNameWithoutLocale) ||
(this.to.name === Router.index && this.$route.name === Router.search)
)
}
get buttonPreset() {
return this.isSelected ? 'primary' : 'plain';
}
}
</script>