I am new to vuejs and I am trying to sync active data to parent but getting an error as
vue.js:523 [Vue warn]: Avoid mutatin
As the error suggests, you are trying to change one of the props active
.
Prop being mutated: "active" (found in component )
As props are dynamically sent from parent, they will change whenever parent changes those, if you change them in child also, there will be conflict, thats why you are getting this error.
As par the documentation:
the parent-child component relationship can be summarized as props down, events up. The parent passes data down to the child via props, and the child sends messages to the parent via events.
So the proper way to do this will be to emit an event, which will call a method in parent and change the variable active
in parent where it is defined. Following will be the code changes: