grapoza / vue-tree

Tree components for Vue 3
MIT License
95 stars 12 forks source link

initial-model not reacting to new data #323

Open moyalmic opened 7 months ago

moyalmic commented 7 months ago

Version is v5.2.2

I'm trying to create a reactive array that would cause the tree view to update every time the data changes but i'm having trouble getting the component to refresh. I've created a computed value called files that maps strings to nodes (giving it a unique id) and when I create a list object using v-for, the list updates properly, but I can't get the tree-view component to update itself with the new data. image

Could somebody please tell me what i'm doing wrong? Does initial-model not update after being set once? Please help me out! Many thanks!

grapoza commented 7 months ago

Hey @moyalmic , I've been trying to set up a StackBlitz for this but apparently the internet is even slower than I thought here and pages keep timing out on me. I never thought I would miss the internet this much... :)

The initial computed value is only applied once in this case because the actual computed value that is initially set changes. If it was a ref instead of a computed and you used a watch to update the ref's value then the tree would see those updates (because that ref object isn't changing, just it's value). I'm hoping that makes sense; this is where the actual example would have been helpful.

moyalmic commented 7 months ago

It does make sense, I've tried rewriting it using a ref and a watch and again, it seems to be updating correctly when I debug it and log the resulting list to the console, but the tree itself isn't changing reactively :( image

Also the first comment under this Stack Overflow post says it's discouraged to use watch in favor of computed properties (especially on arrays which I am doing here)...