2021-01-22 06:24:50 +08:00
|
|
|
<template>
|
|
|
|
<v-list dense>
|
2021-03-21 12:22:10 +08:00
|
|
|
<slot name="pre" />
|
2021-02-07 13:44:53 +08:00
|
|
|
<template v-for="(control, index) in controls">
|
|
|
|
<v-list-item
|
|
|
|
v-if="!control.isDivider"
|
|
|
|
:key="control.title"
|
|
|
|
link
|
|
|
|
:to="isRouterLink(control) ? control.link : null"
|
|
|
|
:nuxt="isRouterLink(control)"
|
|
|
|
:href="isRouterLink(control) ? null : control.link"
|
2021-02-08 06:06:06 +08:00
|
|
|
exact
|
2021-02-07 13:44:53 +08:00
|
|
|
@click="control.action ? control.action() : null"
|
|
|
|
>
|
|
|
|
<v-list-item-icon>
|
|
|
|
<v-icon color="white">{{ control.icon }}</v-icon>
|
|
|
|
</v-list-item-icon>
|
|
|
|
<v-list-item-content>
|
|
|
|
<v-list-item-title>{{ control.title }}</v-list-item-title>
|
|
|
|
</v-list-item-content>
|
|
|
|
</v-list-item>
|
|
|
|
<v-divider v-else :key="index" class="my-2" />
|
|
|
|
</template>
|
2021-03-21 12:22:10 +08:00
|
|
|
<slot name="post" />
|
2021-01-22 06:24:50 +08:00
|
|
|
</v-list>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-03-14 15:34:00 +08:00
|
|
|
import { Component, Prop, Vue } from 'nuxt-property-decorator';
|
2021-01-22 06:24:50 +08:00
|
|
|
import { PropType } from 'vue';
|
2021-01-23 06:36:52 +08:00
|
|
|
import { TranslateResult } from 'vue-i18n';
|
2021-01-22 06:24:50 +08:00
|
|
|
|
|
|
|
export interface Control {
|
2021-02-07 13:44:53 +08:00
|
|
|
icon?: String;
|
|
|
|
title?: String | TranslateResult;
|
2021-01-22 11:11:24 +08:00
|
|
|
link?: String;
|
|
|
|
action?: Function;
|
2021-02-07 13:44:53 +08:00
|
|
|
isDivider?: boolean;
|
2021-01-22 06:24:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component
|
2021-01-24 04:27:15 +08:00
|
|
|
export default class Dropdown extends Vue {
|
2021-01-22 06:24:50 +08:00
|
|
|
@Prop({ type: Array as PropType<Control[]>, required: true })
|
2021-01-22 07:08:06 +08:00
|
|
|
controls!: Control[];
|
2021-01-22 06:24:50 +08:00
|
|
|
|
|
|
|
isRouterLink(control: Control): Boolean {
|
2021-01-22 11:11:24 +08:00
|
|
|
return !!control.link && control.link.startsWith('/');
|
2021-01-22 06:24:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|