I'm writing a recursive tree renderer and suffering this "Avoid mutating props directly" warning.
As I understand it, "props down, events up" means a child can't/shouldn't directly change parent data. I can avoid this error by writing lots of code where one component $emits a change, its parent catches it and re-emits it, and on and on, up to the top level component which finally can change the data, which then renders down through the tree. While I get the use case where a generic component needs to be agnostic of its parent, for a recursive component it seems terribly inefficient.
I noticed an official VueJs 2 tree view example is provided. But looking at that code shows that the child components are passed an object belonging to the parent, yet the child component is allowed to update it directly (e.g. in the addChild or changeType methods).
I made a variation of that jsfiddle as proof. All my variation does is outputs the parent's data as json so you can see it is changed. At the start it looks like this:
{"name":"My Tree","children":[{"name":"hello"},{"name":"wat"}
Then if you click into the first parent, then double click 1. hello to trigger changeType you'll notice the parent's data is now changed:
{"name":"My Tree","children":[{"name":"hello","children":[{"name":"new stuff"}]},{"name":"wat"}...
...yet the dreaded "Avoid mutating a prop directly" warning was not fired.
So I'm obviously missing some nuance. It's frustrating because there's so many questions about this and I'm afraid of adding a duplicate. But I feel this is different because I'm asking "why is the example given not mutating a prop directly"?!