Skip to content

Instantly share code, notes, and snippets.

@nyk510
Created December 30, 2019 04:36
Show Gist options
  • Save nyk510/2e11526d3549d1211e85eee6b2c0e577 to your computer and use it in GitHub Desktop.
Save nyk510/2e11526d3549d1211e85eee6b2c0e577 to your computer and use it in GitHub Desktop.
method status
<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>
@nyk510
Copy link
Author

nyk510 commented Dec 30, 2019

Peek 2019-12-30 13-32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment