0

I've had a problem

  data() {
    return {
      list: [],
      initState: { id: null, data: null }
    }
  },
  computed: {    
     ...mapState({
        contacts: (state) => state.ContactBook.Contacts
      })
     },},
      methods: {
        setinitState(payload) {
          this.initState.data = contacts[this.contactID]
        },

How Can I make this.initState static? I need this.initState didnt changes when contacts[this.contactID] changes...

Padavan
  • 103
  • 2
  • 10
  • 2
    Does this answer your question? [How do I correctly clone a JavaScript object?](https://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object) – Sumurai8 Sep 07 '20 at 17:39

2 Answers2

1

You may use the spread operator like this,

this.initState.data = {...contacts[this.contanctID]}

Spread Operator MDN

dsfx3d
  • 372
  • 2
  • 12
0

state.snapshot = JSON.parse(JSON.stringify(state.Contacts[payload]))

Padavan
  • 103
  • 2
  • 10