提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<div class="category-list"> |
|
3 |
<div class="category" v-for="category in categoryList" :key="category"> |
|
4 |
<el-button |
|
5 |
plain |
|
6 |
round |
|
7 |
size="small" |
|
8 |
:type="category === active ? 'primary' : ''" |
|
9 |
@click="handleCategoryClick(category)" |
|
10 |
> |
|
11 |
{{ category }} |
|
12 |
</el-button> |
|
13 |
</div> |
|
14 |
</div> |
|
15 |
</template> |
|
16 |
<script setup lang="ts"> |
|
17 |
import { PropType } from 'vue' |
|
18 |
|
|
19 |
// 定义属性 |
|
20 |
defineProps({ |
|
21 |
categoryList: { |
|
22 |
type: Array as PropType<string[]>, |
|
23 |
required: true |
|
24 |
}, |
|
25 |
active: { |
|
26 |
type: String, |
|
27 |
required: false, |
|
28 |
default: '全部' |
|
29 |
} |
|
30 |
}) |
|
31 |
|
|
32 |
// 定义回调 |
|
33 |
const emits = defineEmits(['onCategoryClick']) |
|
34 |
|
|
35 |
/** 处理分类点击事件 */ |
|
36 |
const handleCategoryClick = async (category: string) => { |
|
37 |
emits('onCategoryClick', category) |
|
38 |
} |
|
39 |
</script> |
|
40 |
<style scoped lang="scss"> |
|
41 |
.category-list { |
|
42 |
display: flex; |
|
43 |
flex-direction: row; |
|
44 |
flex-wrap: wrap; |
|
45 |
align-items: center; |
|
46 |
|
|
47 |
.category { |
|
48 |
display: flex; |
|
49 |
flex-direction: row; |
|
50 |
margin-right: 10px; |
|
51 |
} |
|
52 |
} |
|
53 |
</style> |