javascriptvue.jsvue-teleport

VueJs Teleport To Style - Script Tag


I want the admin to be able to use their own custom codes on the site such as Google Analytic code. So I try to use teleport to script and style tag like this;

Index.html;

<script id="custom-js"></script>
<style id="custom-css"></style>

App.vue;

<teleport to="#custom-css" v-html="custom.css"></teleport>
<teleport to="#custom-js" v-html="custom.js"></teleport>

But it's not working. What can I do? Is there another way to do that?


Solution

  • The problem in your code is v-html accepts string only, not a file path, v-html is mostly like innerHTML attribute of the DOM element.