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

188
Views
convert similar computed properties to use just one

I have those 3 computed properties is it possible to make them in just one ?

    first() {
      const mydate1 = new Date();
      mydate1.setDate(mydate1.getDate() + 1);
      return mydate1;
    },
    second() {
      const mydate2 = new Date();
      mydate2.setDate(mydate2.getDate() + 2);
      return mydate2;
    },
    third() {
      const mydate3 = new Date();
      mydate3.setDate(mydate3.getDate() + 3);
      return mydate3;
    },    

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

0

This is perfectly okay for a computed property...

dates() {
  const baseDate = new Date().getDate();

  const first = new Date();
  first.setDate(baseDate + 1);

  const second = new Date();
  second.setDate(baseDate + 2);

  const third = new Date();
  third.setDate(baseDate + 3);

  return { first, second, third };
},    

Previous references to, say, second, can change to dates.second. Same for all three.

about 4 years ago · Juan Pablo Isaza Report

0

Instead of using computed properties, why not make a method getDate(offset) that returns a new Date?

methods: {
  getDate(offset) {
    const myDate = new Date();
    myDate.setDate(myDate.getDate() + offset);
    return myDate;
  }
}
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!