[Vuejs]-Set property and retrieve HTML as string from Vue component

1👍

Updating the DOM takes time, you are immediately getting the myDetails outerHTML after you are changing its data, which doesn’t give time for the change to propagate. Setting a slight delay as follows will give output as expected:

handleClick() {
    this.$refs.myDetails.setMessage(new Date().getTime());
    setTimeout(() => {
        this.message = this.$refs.myDetails.$el.outerHTML;
    }, 100) 
}

For demo, see the sandbox here

👤Psidom

Leave a comment