I have a component inside a route-view which is in turn part of another route-view so the tree is like this:
<app>
<appContainer> // This is a route-view
<myView> // Also a route-view
<myComponent>
In myComponent I have this conditional rendering:
<b-button v-if="isAdmin(currentUser)'">
This function is exhibiting unexpected behaviors
isAdmin(username) {
let userObject = this.$store.getters.getCurrentUserObject(username)
return userObject.role === 'ADMIN'
}
The userObject was turning up as undefined until I added a debugger inside the function and realized that this it's being called multiple times during page rendering some of which the store data property is still empty resulting in getters returning null. What could be the reason? Why is this method called multiple times?
PS: I have a for loop in the component, could this be the reason?
<div v-for="bike in bikes":key="bike.timestamp">
<p>{{ bike.name }}</p>
<b-img fluid v-if="bike.imagePath" v-bind:src="returnImage(bike.imagePath)"></b-img>
<p>{{ bike.timestamp}}</p>
</div>
This is called in the created hook
created() {
this.getBikes()
}