Why does adding Date doesnt work but subtract date works? Vue.js

Viewed 47

I'm adding 1 Week on this.currentDate. Problem: subWeek() is working but addWeek() doesnt work.

Every other operator except '+' is working.

this is my vue.js component:

<template>
<div>
...
 <button @click="addWeek()">test
 <button @click="subWeek()">test
...
</div>
</template>

...

 methods: {

    addWeek(){
      showAjaxLoading(true);
      this.currentDate = new Date(this.currentDate.setDate(this.currentDate.getDate()  + 6));
      console.log(this.currentDate);
      showAjaxLoading(false);
    },
    subWeek(){
      showAjaxLoading(true);
      this.currentDate = new Date(this.currentDate.setDate(this.currentDate.getDate() - 6));
      showAjaxLoading(false);
    },
},
created() {
    this.currentDate = new Date();
},
 data(){
    return {
      currentDate : null,

    }
  },

Excpected output:

window output: this.currentDate : 2021-07-21

after button click on addWeek:

window output: this.currentdate : 2021-07-28

Real output:

window output: this.currentDate : 2021-07-21

after button click on addWeek:

window output: this.currentdate : 2021-07-21

console.log output: 2021-07-28

after second button click on addWeek:

window output: this.currentdate : 2021-07-21

console.log output: 2021-07-28

0 Answers
Related