0

in the data function I have created tomorrow variable with the date of today then I have set it by appenden 1 day to it but I'm getting this error

data(){
return{
  tomorrow: new Date(),
  tomorrow.setDate(tomorrow.getDate() + 1),
};
},

error Parsing error: Unexpected token .

1
  • As a WAG, try removing the semi-colon on the 4th line. It's illegal in the JSON or Tuple, or whatever that data structure that is. Commented Dec 8, 2021 at 23:54

1 Answer 1

3

The data property is design for storing variables, not invoking functions or adding logic like you're trying to do.

Try computed property:

computed: {
  tomorrow() {
    const d = new Date()
    d.setDate(d.getDate() + 1)
    return d 
  }
}

And then in your template you can do {{ tomorrow }} or in your vue component this.tomorrow

Sign up to request clarification or add additional context in comments.

2 Comments

I have a question, under computed property is it possible to create multiple variable with the same type ? exp: let aa, bb = new Date ();
Yes, its just normal javascript with vuejs component around it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.