I'm currently working on a project in vue.js where I need to filter elements of an object based on a specific condition.
I want to only return items where maxPeoples are greater than or equal to the input value.
Below is a snippet of my code:
model:
template:
<template>
<div id="app">
<Titre />
<div class="flex justify-around" v-if="maxPeoples === ''">
<input type="text" v-model="maxPeoples" placeholder="set maxPeoples" @keyup.enter="setMaxPeople">
<div v-for="recipe in recipes" :key="recipe.id">
<recipe :picture="recipe.picture" :title="recipe.title" :preparation="recipe.preparation" :people="recipe.people" />
</div>
</div>
</div>
</template>
script:
export default {
name: 'App',
data() {
return {
maxPeoples: '',
recipes: [
{
id: 1,
picture: 'https://picsum.photos/id/100/100/60',
title: 'Macaronis au fromage',
preparation: 15,
people: 2
},
{
id: 2,
picture: 'https://picsum.photos/id/110/100/60',
title: 'Croque-monsieur',
preparation: 10,
people: 1
}
]
}
},
methods: {
setMaxPeoples(maxPeoples){
this.recipes.filter(recipe => recipe.people >= maxPeoples);
}
}
}
I'm encountering an error message:
Failed to compile.
./src/App.vue
Module Error (from ./node_modules/eslint-loader/index.js):
C:\Users\rollivier\Desktop\Franck\dicolor\vue\test-vue\src\App.vue
75:29 error 'recipe' is defined but never used no-unused-vars
✖ 1 problem (1 error, 0 warnings)
I suspect that the forEach loop is causing the issue...
Thank you for your help.