mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 21:16:31 +00:00
54 lines
1.2 KiB
Vue
54 lines
1.2 KiB
Vue
<template>
|
|
<div class="form-control w-full">
|
|
<label class="label">
|
|
<span class="label-text">{{ label }}</span>
|
|
</label>
|
|
<select class="select select-bordered" v-model="value">
|
|
<option disabled selected>Pick one</option>
|
|
<option v-for="obj in items" :value="obj">
|
|
{{ name != '' ? obj[name] : obj }}
|
|
</option>
|
|
</select>
|
|
<!-- <label class="label">
|
|
<span class="label-text-alt">Alt label</span>
|
|
<span class="label-text-alt">Alt label</span>
|
|
</label> -->
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
const emit = defineEmits(['update:modelValue']);
|
|
const props = defineProps({
|
|
label: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
modelValue: {
|
|
type: Object as any,
|
|
default: null,
|
|
},
|
|
items: {
|
|
type: Array as () => any[],
|
|
required: true,
|
|
},
|
|
name: {
|
|
type: String,
|
|
default: 'name',
|
|
},
|
|
selectFirst: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
});
|
|
|
|
watchOnce(
|
|
() => props.items,
|
|
() => {
|
|
if (props.selectFirst && props.items.length > 0) {
|
|
value.value = props.items[0];
|
|
}
|
|
}
|
|
);
|
|
|
|
const value = useVModel(props, 'modelValue', emit);
|
|
</script>
|