I have a specific input tag with the model selectedProp
:
<input type="text" v-model="selectedProp" />
and I need to loop through items in this manner:
<div v-for="item of filteredItems">{{item.prop}}</div>
Below is the code snippet for the component:
export default {
name: 'App',
data() {
return {
items: [],
selectedProp: "",
projects: [],
errors: []
}
},
created() {
axios.get(`${URL}`)
.then(response => {
// JSON responses are automatically parsed.
this.items = response.data;
})
.catch(e => {
this.errors.push(e)
});
},
computed: {
filteredItems() {
if(this.selectedProp) {
console.log(this.selectedProp);
return this.items.filter(function (item) {
return item.prop == this.selectedProp;
});
}
return this.items;
}
},
}
An Issue
The value of 'this' is not defined within the computed property