Skip to content

naja in Vue instance, works only for first attempt #369

Answered by emololftw
emololftw asked this question in Support
Discussion options

You must be logged in to vote

I came back to this problem after almost a year and a half and finally found an elegant solution to reinitialize vue components inside a snippet thanks to my experience.

I had also problem with redrawing vue components inside snippets. This is universal solution for both situations:

let snippetInstances = {}

naja.snippetHandler.addEventListener('beforeUpdate', (event) => {
    const id = event.detail.snippet.id;
    let instance = snippetInstances[id] ?? null;
    if (instance) {
        instance.unmount();
    }
})

naja.snippetHandler.addEventListener('afterUpdate', (event) => {
    const el = event.detail.snippet;
    let instance = createMyApp(el.id);
    snippetInstances[el.id] = in…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@jiripudil
Comment options

Comment options

You must be logged in to vote
1 reply
@jiripudil
Comment options

Answer selected by emololftw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants