lundi 9 septembre 2019

Vue method scope, return from if statement not returning

I want to return true/false from a Vue method depending on user role check inside v-for and the method is not returning from if statement.

First, template is like this (simplified)

<div v-for="user in users" :key="user.id">
 <div :contenteditable="checkuser(user)"></div>
</div>

I just need true/false and this is the checkMethod

This doesn't work

    checkUser(user) {
      if (user.admin) {
        return user.team_id === this.$store.state.user.team_id;

       // I would expect to return from method here and not continue execution
       // also, any variables (even declared outside if) are not modified    

     }

      if (user.deleg) {
        return user.subteam_id === this.$store.state.user.subteam_id;
      }

      // method ends here
    }

I know this is stupid and simple but I cant get it working. If there is only one check it works ok obviously but I want to check it for 2 roles. Admin has also deleg permission so if user is admin it doesnt need to check for deleg, but if he doesnt have admin it should check for deleg.

Aucun commentaire:

Enregistrer un commentaire