| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <template>
- <!-- 单选标签选择按钮条,可显示一行标签,然后高亮选中项 -->
- <div class="d-flex flex-row flex-wrap">
- <div
- :class="[
- 'tag-button',
- { 'active': tag.id === selectedTag },
- ]"
- v-for="tag in tags"
- :key="tag.id"
- @click="emit('update:selectedTag', tag.id ?? tag)"
- >
- {{ tag.name?? tag }}
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import type { PropType } from 'vue';
- defineProps({
- /**
- * 标签列表
- */
- tags: {
- type: Object as PropType<Array<{
- id: number|string,
- name: string,
- }>>,
- required: true,
- },
- /**
- * 选中的标签,可双向绑定
- */
- selectedTag: {
- type: [Number,String],
- default: null,
- }
- })
- const emit = defineEmits([
- "update:selectedTag"
- ])
- </script>
- <style lang="scss">
- @use '@/assets/scss/colors.scss' as *;
- .tag-button {
- display: flex;
- flex-direction: row;
- align-items: center;
- background-color: $box-inset-color;
- color: $text-color;
- padding: 10px 15px;
- margin-right: 8px;
- cursor: pointer;
- user-select: none;
- &:hover {
- background-color: $box-hover-color;
- }
- &:active, &.active {
- color: $text-color-light;
- background-color: $primary-color;
- }
- }
- </style>
|