Skip to content

Instantly share code, notes, and snippets.

@cristofersousa
Created September 5, 2020 00:00
Show Gist options
  • Save cristofersousa/acd4bc47797eaa2bac04026eb9fc80a1 to your computer and use it in GitHub Desktop.
Save cristofersousa/acd4bc47797eaa2bac04026eb9fc80a1 to your computer and use it in GitHub Desktop.
Computed Basics Example - Vue
<template>
<div class="about">
<h1>This is an about page</h1>
<ul>
<li v-for="banana in filterBanana" :key="banana.id">
{{ banana }}
</li>
</ul>
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: 'Home',
data() {
return {
frutas: [
{ id: 1, name: 'banana-maca' },
{ id: 2, name: 'banana-prata' },
{ id: 3, name: 'maça' },
{ id: 4, name: 'pera' },
{ id: 5, name: 'uva' },
{ id: 6, name: 'uva2' },
{ id: 7, name: 'pessego' },
{ id: 8, model: 'jaca' },
],
};
},
computed: {
filterBanana() {
const filterFruit = this.frutas.filter(({ name }) => name === 'uva');
return filterFruit;
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment