I didn't see an answer to this that compared the two but please shoot me in the right place if there is.
I have two working examples of re-rendering a component in a Vue 3 application at present and wanted some advice on which method might be better and why.
Essentially, I have a child grid component that loads data from an API. In the parent component, we listen for an event, perform an action and then re-render the component.
Method 1
The first method is that we apply a ref
called grid
to the child component, and when we listen for @custom-event
in the parent, we call that ref and then subsequently a method on it called refreshGrid
- this calls the child grid instance method called refreshGrid
which just calls a DevExtreme method to reload the data (ultimately triggering a call to the API again). This method seems clunky and jumps about between the two components.
Method 2
We simply add a :key
to the child component, and when we listen for @custom-event
and call the method, we just increment the key by 1, forcing Vue to reload the component.
I'm not sure whether the second method would cause more overhead than the first, as the first method eventually calls a method on DevExtreme to just reload the component.
Any advice would be appreciated.
Cheers