Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
I am having a problem with v-if in a nested loop [vuejs]

My problem is I am trying to edit a role so I have two functions, one to bring back the role and its permissions and one to bring all permissions. I am trying to do a nested v-for loop to show all permissions and check the one that was already selected. everything works fine but I can't show all permissions for some reason. There is one more permission called "Delete user" that doesn't show up. anyway, the problem is 100% from the template side.

 <div class="container" v-for="(mission,key,index) in permissions" :key="key">
    <div class="form-group" v-for="(per,key,index) in selected" :key="key" v-if="mission.id == per.id">
        <input type="checkbox"  v-model="mission[key]"  checked >{{mission.name}}
        <div v-if="mission.id !== per.id">
        <input type="checkbox"  v-model="mission[key]">{{mission.name}}
        <p>fucking hell</p>
      </div>
   </div>                      
</div>
                    
<script>
export default {
    data(){
        return{
            role:'',
            permissions:[],
            selected:[],
        }
    },
    mounted(){
        this.showRole()
        this.getPermissions()
        
    },
    methods:{
        showRole(){
           
            this.axios.get(`/api/role/${this.$route.params.id}`).then(response=>{
                const{role ,selected}= response.data
                this.role= role
                this.selected = selected
            }).catch(error=>{
                console.log(error)
            })
        },
        getPermissions(){
            this.axios.get('/api/permissions').then(response=>{
                this.permissions =response.data
            }).catch(error=>{
                console.log(error)
            })
        },
    }
}
</script>

here is a picture of the API that returns all permission. you can see delete user is there at the end.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using v-if and v-for together is not recommended. Look at style guide for more info.

When used together with v-if, v-for has a higher priority than v-if.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!