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

212
Views
How to simplify code written with switch in vue.js

how can I simplify this switch? Is there an easier way to write a switch like that? Or to return as in the switch depending on the 5 cases I have?

data() {
        return {
            stepOneIsCompleted: false,
            stepTwoIsCompleted: false,
            stepThreeIsCompleted: false,
            stepFourIsCompleted: false,
            stepFiveIsCompleted: false,
        };
    },
updateViewEditVisibility(step, status) {
            switch (step) {
            case 1:
                status === 200 ? this.stepOneIsCompleted = true : this.stepOneIsCompleted = false;
                break;

            case 2:
                status === 200 ? this.stepTwoIsCompleted = true : this.stepOneIsCompleted = false;
                break;

            case 3:
                status === 200 ? this.stepThreeIsCompleted = true : this.stepOneIsCompleted = false;
                break;

            case 4:
                status === 200 ? this.stepFourIsCompleted = true : this.stepOneIsCompleted = false;
                break;

            case 5:
                status === 200 ? this.stepFiveIsCompleted = true : this.stepOneIsCompleted = false;
                break;
            }
        },

It should be mentioned that I will send those values as props. Couldn't I make an array for example and look in it according to step and assign a value to it?

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

0

data() {
    return {
        stepCompleted: [
            false,  //stepOneIsCompleted
            false,  //stepTwoIsCompleted
            false,  //...
            false,
            false
        ]
    }
}

...

updateViewEditVisibility(step, status) {
    this.stepCompleted[step] = status === 200;
}
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!