Static GitHub Issues

[226] Where should I put the inline script?

prev: The data function has no context parameter in layout component
next: nuxt generate fails with a lot of dynamic routes

for example:

<body>
    <script>
        /* disable-eslint */
        function rem() {
            var w = Math.min(document.documentElement.getBoundingClientRect().width, 500);
            document.getElementsByTagName('html')[0].style.fontSize = w * 100 / 750 + 'px';
        }
        rem();
        window.onresize = function(){rem();};
    </script>
    <div></div>
</body>

I checked the document of vue-meta and use the code below

head: {
    title: 'starter',
    script: [
      { innerHTML: 'document.querySelector("html")' }
    ]
}

But the quotes are escaped in the browser

<script n-head="true">document.querySelector(&quot;html&quot;)</script>

I also try to put the code into the layout component, the quotes are escaped too.

Update:

I carefully checked the document of vue-meta, and solved the problem with

head: {
    title: 'starter',
    script: [
      { innerHTML: 'document.querySelector("html")' }
    ],
    __dangerouslyDisableSanitizers: ['script']
}

Thank you a lot ! I really like this project! 😍

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c191">#c191</a>)</em></sub></div>