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

269
Views
Onclick of checkbox how to add straight line in Vuejs?

<script>
export default {
  name: 'App',
  data() {
    return {
      getQuestionAnswers: [
        {
          name: 'foo',
          checked: false,
          status: 'good'
        },
        {
          name: 'bar',
          checked: false,
          status: 'worst'
        },
        {
          name: 'baz',
          checked: false,
          status: 'good'
        },
        {
          name: 'df',
          checked: false,
          status: 'bad'
        },
        {
          name: 'apple',
          checked: false,
          status: 'worst'
        }
      ]
    }
  }
}
</script>


//ListTwo.vue


<script>
export default {
  name: 'App',
  data() {
    return {
      getQuestionAnswers: [
        {
          name: 'vall',
          checked: false,
          status: 'good'
        },
        {
          name: 'bara',
          checked: false,
          status: 'bad'
        },
        {
          name: 'ssss',
          checked: false,
          status: 'bad'
        },
        {
          name: 'ba',
          checked: false,
          status: 'worst'
        },
        {
          name: 'df',
          checked: false,
          status: 'good'
        },
        {
          name: 'ae',
          checked: false,
          status: 'good'
        },
        {
          name: 'amm',
          checked: false,
          status: 'worst'
        }
      ]
    }
  }
}
</script>
<template>
  <div id="app">
    <div
      class="bcom"
      v-for="(group, index) in getQuestionAnswers"
      :key="index + group.name"
      :group="group"
    >
      <div :class="['container1', { red: group.name === 'bar' }]">
        <input type="checkbox" v-model="group.checked" />
        {{ group.name }}
      </div>
      <div class="container2">
        <div class="h-line" v-if="group.checked">{{ group.status }}</div>
      </div>
    </div>
  </div>
</template>

As you can see in the output of above provided code, I have two section, one is left, right. Both are from different components, and data is different for both.

When click on "foo" from left side, Can I match the right side content status. and draw line (condition is like, whatever status is good draw the lines) is it is multiple also fine.

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

0

I have modified the classNames and the styles. Also have added v-model for the input fields. Pls check the below working code

new Vue({
  el: "#app",
  
  data: {
    getQuestionAnswers: [
        {
        name: 'foo',
        checked: false
      },
      {
        name: 'bar',
        checked: false
      },
      {
        name: 'baz',
        checked: false
      }
    ]
  }
})
body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
  width:100%
}

.red {
  color: red;
}
.bcom {
   width: 100%;
   display: flex;
}
.container1 {
   width: 50px;
 }
 .container2 {
   width: calc(100% - 105px);
   padding: 8px 0;
   height: 30px;
   box-sizing: border-box;
  }
 .h-line {
  height: 1px;
  margin-bottom: 18px;
  width: 100%;
  background-color: black;
 }
.container3{
  margin-left: 5px;
  width: 50px;
}

.point {
  width: 6px;
  height: 6px;
  background: tomato;
  border-radius: 3px;
  transition: width 1s ease;
}

.point:hover {
  width: 200px;
}
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
 <div class="bcom"
    v-for="(group, index) in getQuestionAnswers"
    :key="index + group.name"
    :group="group"
  >
  <div :class="['container1',{ 'red': group.name === 'bar' }]">
   <input type="checkbox" v-model="group.checked"/>
    {{ group.name }}
  </div>
  <div class="container2">
   <div class="h-line" v-if="group.checked"></div>
  </div>
  <div :class="['container3',{ 'red': group.name === 'bar' }]">
  <input type="checkbox" v-model="group.checked"/> 
    {{ group.name }}
  </div>
  </div>
  <div class="point"></div>
</div>

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!