mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
PillBox use Index or option key as modelValue
This commit is contained in:
parent
d7f2eb64f9
commit
c8fada4e0c
1 changed files with 18 additions and 5 deletions
|
@ -3,16 +3,29 @@
|
|||
const props = defineModel<{
|
||||
options: {
|
||||
name: string,
|
||||
key: string,
|
||||
icon: Component,
|
||||
selected: boolean,
|
||||
}[],
|
||||
modelValue: number,
|
||||
modelValue: number | string,
|
||||
useIndex: boolean,
|
||||
}>();
|
||||
let { options, modelValue } = $(props);
|
||||
let { options, modelValue, useIndex } = $(props);
|
||||
|
||||
function setSelection(option: any, index: number){
|
||||
if (useIndex) {
|
||||
modelValue = index
|
||||
} else {
|
||||
modelValue = option.key
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async() => {
|
||||
if (modelValue === undefined) {
|
||||
modelValue = 0
|
||||
if (useIndex) {
|
||||
modelValue = 0
|
||||
} else {
|
||||
modelValue = options[0].key
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -20,7 +33,7 @@ onMounted(async() => {
|
|||
|
||||
<template>
|
||||
<div>
|
||||
<button class="option" v-for="(option, index) in options" :key="index" :class="{selected: modelValue == index}" @click="modelValue = index">
|
||||
<button class="option" v-for="(option, index) in options" :key="index" :class="{selected: modelValue == index || modelValue == option.key}" @click="setSelection(option, index)">
|
||||
<i class="material-icons" v-if="option.icon">{{ option.icon }}</i>
|
||||
{{ option.name }}
|
||||
</button>
|
||||
|
|
Loading…
Add table
Reference in a new issue