diff --git a/src/components/Dict/DictLabel.vue b/src/components/Dict/DictLabel.vue index 1ef82bea..c6603470 100644 --- a/src/components/Dict/DictLabel.vue +++ b/src/components/Dict/DictLabel.vue @@ -53,18 +53,14 @@ const updateLabelAndTag = async () => { tagType.value = newTagType as typeof tagType.value; }; -watch([() => props.code, () => props.modelValue], updateLabelAndTag); - -onMounted(updateLabelAndTag); - -// 监听WebSocket字典更新事件,强制刷新标签 +// 初始化或code变化时更新标签和标签样式 watch( - () => dictStore.getDictItems(props.code || ""), + [() => props.code, () => props.modelValue], async () => { if (props.code) { await updateLabelAndTag(); } }, - { deep: true } + { immediate: true } ); diff --git a/src/components/Dict/index.vue b/src/components/Dict/index.vue index ee5f1136..79d98e4d 100644 --- a/src/components/Dict/index.vue +++ b/src/components/Dict/index.vue @@ -120,13 +120,4 @@ onMounted(async () => { await dictStore.loadDictItems(props.code); options.value = dictStore.getDictItems(props.code); }); - -// 监听字典数据变化,确保WebSocket更新时刷新选项 -watch( - () => dictStore.getDictItems(props.code), - (newItems) => { - options.value = newItems; - }, - { deep: true } -);