Created
August 30, 2022 08:48
-
-
Save bas080/1987fa65cd19e6eee794c10d4e8771df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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