Skip to content

Instantly share code, notes, and snippets.

@bas080
Created August 30, 2022 08:48
Show Gist options
  • Save bas080/1987fa65cd19e6eee794c10d4e8771df to your computer and use it in GitHub Desktop.
Save bas080/1987fa65cd19e6eee794c10d4e8771df to your computer and use it in GitHub Desktop.
<template>
<div>
<div v-for="item in items">
<slot v-slot="api(item)"/>
</div>
</div>
<!-- How to use
...
<Options>
<template v-slot:default="{item, select, selected}">
<Card :class="classes(item, selected)" @click="select"></Card>
</template>
</Options>
...
-->
</template>
<script>
export default {
props: {
value: Object, //any
},
methods: {
select(item) {
this.value = item
this.$emit('input', this.value)
},
toggle(item) {
this.select((this.value === item) ? null : item)
},
api(item) {
return {
item,
selected: (this.item === item),
select: this.select.bind(this, item),
toggle: this.toggle.bind(this, item),
}
}
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment