Created
December 30, 2019 04:36
-
-
Save nyk510/2e11526d3549d1211e85eee6b2c0e577 to your computer and use it in GitHub Desktop.
method status
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 class="pa-4"> | |
<v-chip | |
v-for="item in sortedItems" | |
:class="itemClass(item)" | |
:key="item.value" | |
@click="onClickItem(item)"> | |
{{ item.text }} | |
</v-chip> | |
{{ selectedItems }} | |
</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
items: [{ text: 'foo', value: 1 }, { text: 'bar', value: 2 }], | |
selectedItems: [] | |
} | |
}, | |
computed: { | |
sortedItems() { | |
return this.items.slice().sort((a, b) => a.value - b.value) | |
} | |
}, | |
methods: { | |
itemClass(item) { | |
if (this.selectedItems.includes(item)) return 'primary white--text' | |
}, | |
onClickItem(item) { | |
if (this.selectedItems.includes(item)) { | |
this.selectedItems = this.selectedItems.filter( | |
v => v.value !== item.value | |
) | |
return | |
} | |
this.selectedItems.push(item) | |
} | |
} | |
} | |
</script> |
Author
nyk510
commented
Dec 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment