Skip to content

Instantly share code, notes, and snippets.

@paradisetester
Created January 3, 2022 07:52
Show Gist options
  • Save paradisetester/162e0d71042ab4e5f96be8bbb48f9671 to your computer and use it in GitHub Desktop.
Save paradisetester/162e0d71042ab4e5f96be8bbb48f9671 to your computer and use it in GitHub Desktop.
computed property "activeItems" done.
<template>
<div class="widget">
<div v-if="activeItems && activeItems.length > 0">
<ul>
<li v-for="item in activeItems" :key="item.id">
{{ item.name }}
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
data() {
return {
loading: true,
list: {
John: true,
Jane: true,
Bob: false,
},
};
},
computed: {
activeItems() {
var arr_list = [];
for (const [key, value] of Object.entries(this.list)) {
if (value) {
var val = {
name: key,
active: value,
};
arr_list.push(val);
}
}
return arr_list;
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment