index.vue
974 Bytes
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
<template>
<div>
<a-space>
<template v-for="(item, index) in props.options" >
<template v-if="values.includes(item.value)">
<a-tag
:key="item.id"
:index="index"
:color="item.listClass ? item.listClass : 'rgb(var(--primary-6))'"
>{{item.label}}</a-tag
>
</template>
</template>
</a-space>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
const props = defineProps({
// 数据
options: {
type: Array,
default: null,
},
// 当前的值
value: [Number, String, Array],
// 当未找到匹配的数据时,显示value
showValue: {
type: Boolean,
default: true,
},
})
const values = computed(() => {
if (props.value !== null && typeof props.value !== "undefined") {
return Array.isArray(props.value) ? props.value : [String(props.value)];
} else {
return [];
}
});
</script>
<style scoped lang="less">
</style>