[Vuejs]-Why are Vue dynamic components destroyed inside loop every re-render?

0👍

I found out why, I need to use keep-alive:

https://v2.vuejs.org/v2/guide/components-dynamic-async.html

To quote:

When switching between these components though, you’ll sometimes want
to maintain their state or avoid re-rendering for performance reasons

Recreating dynamic components is normally useful behavior, but in this
case, we’d really like those tab component instances to be cached once
they’re created for the first time. To solve this problem, we can wrap
our dynamic component with a element

Wasted 2 days on this issue and then I found the answer just a moment after posting this on StackOverflow. Hope it helps someone.

Leave a comment