V-html inner script tag execution

Hello,

Despite how obvious bad practice is it - I wonder if it is possible to execute inner script tag when it comes into DOM trough v-html. I mean behaviour similar to http://api.jquery.com/load/#script-execution. I’m working on legacy app written in prototype (something like jQuery ancestor) which executes response js by default (http://prototypejs.org/learn/introduction-to-ajax.html - Evaluating a JavaScript response).

Thank You,
Paweł

2 Likes

I’m experiencing same issue. In my case I am rendering posts feed and some posts contain oEmbeds, and some oEmbed providers (at least Facebook and Instagram) rely on injecting their scripts into the page as part of oEmbed content to properly style their content and to make it interactive. Unfortunately rendering it with v-html doesn’t work as Vue puts <script> tags into the DOM but they neither load nor execute the js-code. I wonder if there’s any workaround for this?

Hi, I was having a similar issue to this. Vue uses innerHTML to set the content passed via v-html. Apparently innerHTML does not execute scripts when it changes. I found this stackoverflow question about it.

Any recipe about how to make it work?

It’s three years from the last message but I still haven’t found any solution if any got a recipe it will be welcome :grinning: