0

I have a function called when i am trying to update the date but i am getting an error

updateDate(value, id){
      let data = [...this.preauthenticationdata];
      const index = data.findIndex(row => row.id == id)
      data[index].dateInput = value
      this.keyInputDate++
      this.SET_ppreauthenticationdata(data);
    }

i a trying to call this on the following

@input="updateDate($event, props.row.id)"

the issue is i am getting an error

Error: [vuex] do not mutate vuex store state outside mutation handlers.

what is wrong i am doing here

i have updated the code above as to what i am doing and why it is throwing me an error

  • what is the code for `SET_ppreauthenticationdata`? – XMehdi01 Jun 29 '23 at 14:58
  • 1
    `data` is a shallow copy of `this.preauthenticationdata` and you're directly modifying an object in `data`. – Dave Newton Jun 29 '23 at 15:00
  • Dave has the right of it. To elaborate, object values are copied by reference instead of by value during shallow copies. `data[index].dateInput = value` is the same as `this.preauthenticationdata[index].dateInput = value`. You need to [deep copy](https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy) first to avoid the error – yoduh Jun 29 '23 at 15:12
  • so how do i do the deep copy – Smith Jonas Jun 29 '23 at 15:15
  • 1
    https://stackoverflow.com/a/23481096/6225326 – yoduh Jun 29 '23 at 15:24

0 Answers0