Skip to content

Commit 937b86a

Browse files
refactor: migrate VDropDown to TypeScript
1 parent 0bc142f commit 937b86a

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/components/pivottable-ui/VDropdown.vue

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,44 @@
77
v-for="(text, key) in options"
88
:key="key"
99
:value="text"
10-
:selected="text === valueModel ? 'selected' : undefined"
1110
>
1211
{{ text }}
1312
</option>
1413
</select>
1514
</template>
1615

17-
<script setup>
16+
<script setup lang="ts">
1817
import { ref, watch } from 'vue'
1918
20-
const props = defineProps({
21-
options: {
22-
type: Array,
23-
default: () => []
24-
},
25-
value: {
26-
type: String,
27-
default: ''
28-
}
19+
const emit = defineEmits<{
20+
(event: 'update:value', value: string): void
21+
}>()
22+
23+
interface DropdownProps {
24+
options: string[]
25+
value: string
26+
}
27+
28+
const props = withDefaults(defineProps<DropdownProps>(), {
29+
options: () => [],
30+
value: ''
2931
})
30-
const valueModel = ref(props.value || props.options[0])
31-
const emit = defineEmits(['update:value'])
32+
33+
const valueModel = ref<string>('')
34+
35+
watch(
36+
[() => props.value, () => props.options],
37+
([val, opts]: [string, string[]]) => {
38+
valueModel.value = val || opts[0] || ''
39+
},
40+
{ immediate: true }
41+
)
42+
3243
watch(
3344
valueModel,
34-
(newVal) => { emit('update:value', newVal) },
45+
(newVal) => {
46+
emit('update:value', newVal)
47+
},
3548
{ immediate: true }
3649
)
3750
</script>

0 commit comments

Comments
 (0)