Skip to content

Commit de21b91

Browse files
authored
Merge branch 'master' into branch_bertcai
2 parents 45f5698 + 136df73 commit de21b91

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

docs/.vitepress/components/BTagSelector/multi.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<BTagSelector v-model:selectedList="flavour" :options="flavourList" label="计数" tagKey="value" @selectorChange="handleChange">
2+
<BTagSelector v-model:selectedList="flavour" :options="flavourList.length > 0 ? flavourList : [{ value: '烤鸭我喜欢有葱丝的', label: '葱丝' }, { value: '烤鸭我喜欢有黄瓜丝的', label: '黄瓜丝' }]" label="计数" tagKey="value" @selectorChange="handleChange">
33
<template v-slot:header>
44
<div class="title-text">选中tag计数: {{ flavour.length }}</div>
55
</template>
@@ -22,7 +22,7 @@
2222
<script setup lang="ts">
2323
import { BTagSelector } from '@fesjs/traction-widget';
2424
import { FSelect } from '@fesjs/fes-design';
25-
import { ref, computed } from 'vue';
25+
import { ref, computed, onMounted } from 'vue';
2626
2727
// 选择器所绑定的数据
2828
const city = ref<string>('');
@@ -60,6 +60,11 @@ const handleCityChange = () => {
6060
const handleChange = (val: any) => {
6161
console.log(val);
6262
};
63+
64+
onMounted(() => {
65+
flavour.value = ['烤鸭我喜欢有葱丝的', '烤鸭我喜欢有黄瓜丝的'];
66+
});
67+
6368
</script>
6469
<style scoped>
6570
.title-text {

packages/traction-widget/components/TagSelector/TagSelector.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</div>
2929
</template>
3030
<script setup lang="ts">
31-
import { defineProps, defineEmits, computed, useSlots, ref } from 'vue';
31+
import { defineProps, defineEmits, computed, useSlots, ref, watch } from 'vue';
3232
import { FTag, FSelect } from '@fesjs/fes-design';
3333
import { useLocale } from '../hooks/useLocale';
3434
@@ -81,14 +81,15 @@ const deleteTag = (item: any, index: number) => {
8181
const cacheOptions = ref<any[]>([]);
8282
const isSlotHeader = computed(() => !!useSlots().header);
8383
const handleChange = (val: any) => {
84-
cacheOptions.value.push(...props.options);
84+
emit('selectorChange', val);
85+
};
86+
watch(() => props.options, (oldVal, newVal) => {
87+
cacheOptions.value.push(...(props.options as any[]));
88+
// 基于value去重,保证cacheOptions能保证最小
8589
cacheOptions.value = cacheOptions.value.filter((item, index, self) => {
8690
return self.findIndex(el => el.value === item.value) === index;
8791
});
88-
cacheOptions.value = cacheOptions.value.filter(item => val.includes(item.value));
89-
emit('selectorChange', val);
90-
};
91-
92+
}, { immediate: true });
9293
const handleClear = () => {
9394
selectedList.value = [];
9495
emit('clearAll');

0 commit comments

Comments
 (0)