0
votes

I'm trying to modify a state then push it back to store but it returns me an error

methods : {
  modalBtnClick(index){
    let btns = [];

    this.$store.state.utility.modal_content.btns.forEach((item)=>{
      btns.push(item);
    });

    btns[index].result = true;

    this.$store.commit('utility/modal_content',{
      body : this.$store.state.utility.modal_content.body,
      btns : btns
    });
  }
}

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

Any help, ideas is greatly appreaciated.

1

1 Answers

0
votes

I just did json stringify and then parse back and seems working now

let data = JSON.parse( JSON.stringify( this.$store.state.utility.modal_content ) );

data.btn[index].result = true;

this.$store.commit('utility/modal_content',data');