I have an array having three objects and each object have straight key value pair.
// Search Input
<div class="dv-header-search">
<input type="text" class="dv-header-input"
placeholder="Search"
v-model="query.search_input">
</div>
//Table row
<tr v-for="row in filteredRow">
<td v-for="(value, key) in row">{{value}}</td>
</tr>
data() {
return {
model: {},
columns: {},
query: {
search_input: ''
},
}
},
// Setting model after API call
.then(function(response) {
Vue.set(vm.$data, 'model', response.data.model)
})
computed: {
filteredRow: function(){
return this.model.data.filter((row) => {
return row;
});
}
}
It gives me the following exception :
TypeError: Cannot read property 'filter' of undefined
What Am i missing here.
modeldefinition?modellooks like?modelas an empty object in yourdatamethod. Sothis.model.datais going to beundefined. So in yourfilteredRowcomputed,this.model.data.filteris what's throwing the error.model: { data: [] }and on page load you won't have that error anymore. The promise object is not resolving in time. Alternatively, you can use av-if="model.data !== undefined"if you'd rather have the template handle it.