I am facing an issue where I am trying to call a computed property upon page creation, but it is giving an error stating that it cannot read the data for 'undefined'. This is because the data I require is not fully loaded yet. However, when I delay the function to run 2 seconds after the creation, it works perfectly fine.
Could someone suggest a clean way to ensure that the function runs only once the data variable is set?
<div id="app">
<div v-for="(value, employee) in employeeFunction" :key="employee">
@{{value}}
</div>
</div>
<script>
var vm =
new Vue({
el: "#app",
data: {
results: [
{//data goes here
}
],
},
created: function(){
this.interval = setInterval(() => this.employeeFunction(), 2000);
},
computed: {
employeeFunction() {
console.log('employee data')
employeeResults = this.results
console.log(employeeResults)
return employeeResults
},
}
});
</script>