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

148
Views
Button click to show matching DIV and hide the others, using Vue3

I apologize if question seems dumb. I'm new to Vue.

I have a couple of buttons and a couple of divs. Each button when clicked is supposed to display the matching div while hiding everyone else.

This is what I've done

<!-- Buttons -->
<div v-for="button in buttons" :key="button" @click="showBox(button.link)">
    {{ button.text }}
</div>

<!-- Boxes -->
<div id="about" :class="{ hidden: boxes.about.isHidden }">
    About me
</div>

<div id="resume" :class="{ hidden: boxes.resume.isHidden }">
    Resume
</div>

<div id="contact" :class="{ hidden: boxes.contact.isHidden }">
    Contact
</div>

<script>
    export default {
        components: {
        },
        props: {
        },
        data () {
            return {
                buttons: [
                    { text: 'About', link: 'about' }, 
                    { text: 'Resume', link: 'resume' },
                    { text: 'Contact', link: 'contact' },
                ],
                boxes: {
                    about: { isHidden: false },
                    resume: { isHidden: true },
                    contact: { isHidden: true },
                }
            }
        },
        methods: {
            showBox(box) {
                boxes.box.isHidden = false
            }
        }
    }
</script>

As you can see, per default the About -box is visible, but I'm not sure how to continue from here. The showBox() method doesn't work when I put the varible (box) I passed from the click-function and place it like that. I'm also not sure how I best hide the rest of the boxes. Do I loop through the objects and set all isHidden to true?

Appreciate any help.

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

0

You can access data with the this keyword. You need to fixed it with this.boxes[box].isHidden = false

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!