mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 19:08:20 +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<{
|
const props = defineModel<{
|
||||||
options: {
|
options: {
|
||||||
name: string,
|
name: string,
|
||||||
|
key: string,
|
||||||
icon: Component,
|
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() => {
|
onMounted(async() => {
|
||||||
if (modelValue === undefined) {
|
if (modelValue === undefined) {
|
||||||
modelValue = 0
|
if (useIndex) {
|
||||||
|
modelValue = 0
|
||||||
|
} else {
|
||||||
|
modelValue = options[0].key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,7 +33,7 @@ onMounted(async() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<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>
|
<i class="material-icons" v-if="option.icon">{{ option.icon }}</i>
|
||||||
{{ option.name }}
|
{{ option.name }}
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Reference in a new issue