Created
January 3, 2022 07:52
-
-
Save paradisetester/162e0d71042ab4e5f96be8bbb48f9671 to your computer and use it in GitHub Desktop.
computed property "activeItems" done.
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="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