refactoring

This commit is contained in:
Philipp Kühn 2021-01-18 17:02:03 +01:00 committed by Hans Pagel
parent a7ac9a7ef4
commit b4032a17cb

View File

@ -1,13 +1,14 @@
<template> <template>
<div class="items"> <div class="items">
<div <button
class="item" class="item"
:class="{ 'is-selected': index === selectedIndex }" :class="{ 'is-selected': index === selectedIndex }"
v-for="(item, index) in items" v-for="(item, index) in items"
:key="index" :key="index"
@click="selectItem(index)"
> >
{{ item }} {{ item }}
</div> </button>
</div> </div>
</template> </template>
@ -18,6 +19,11 @@ export default {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
command: {
type: Function,
default: () => true,
},
}, },
data() { data() {
@ -61,10 +67,14 @@ export default {
}, },
enterHandler() { enterHandler() {
const item = this.items[this.selectedIndex] this.selectItem(this.selectedIndex)
},
selectItem(index) {
const item = this.items[index]
if (item) { if (item) {
console.log('select', item) this.command(item)
} }
}, },
}, },
@ -85,6 +95,11 @@ export default {
; ;
} }
.item { .item {
display: block;
width: 100%;
text-align: left;
background: transparent;
border: none;
padding: 0.2rem 0.5rem; padding: 0.2rem 0.5rem;
&.is-selected, &.is-selected,