Files
LinyeZhanshi/src/components/IndicatorSelector.vue
TigerNiu acdec7e776 11.6
2025-11-06 10:58:16 +08:00

35 lines
733 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<label>选择指标</label>
<select v-model="localValue">
<option v-for="ind in indicators" :key="ind" :value="ind">{{ ind }}</option>
</select>
</div>
</template>
<script setup>
import { ref, watch } from "vue";
const props = defineProps({
indicators: Array,
modelValue: String,
});
const emit = defineEmits(["update:modelValue"]);
// 创建本地变量副本
const localValue = ref(props.modelValue);
// 当父组件传值变化时,同步更新本地变量
watch(
() => props.modelValue,
(val) => {
localValue.value = val;
}
);
// 当选择变化时,向父组件同步
watch(localValue, (val) => {
emit("update:modelValue", val);
});
</script>