Skip to content

[solved] re-mount & render App + child components after DOM "destruction" by (external) .innerHTML #1476

Closed Answered by WebMechanic
WebMechanic asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, so the solution was annoyingly simple.

Since Vue can't/won't tell it lost its connection to the real DOM, using a MutationObserver is key to the solution.

The $el property of each component is still holding a fully functional copy of the "original" element in its rendered state incl. all the children, read: their connection to the actual document might be broken, but it's still intact within the "subtree" owned by the application's top level $el.

When the MutationObserver's handler is called, all you need to do is put the app's element back into the DOM, replacing the new but vanilla DOM element that was created due to the innerHTML result.

Here are the essential bits in the applicati…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by WebMechanic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant