NUXT将RAW(静态)HTML添加到组件

发布于 2025-02-05 06:17:05 字数 674 浏览 1 评论 0原文

在例如

<!doctype html>
<html lang="en" data-n-head="...">
<head>...nuxt generated head...</head>
<script>
    // this tag needs to exist as html when building with 'yarn generate'
    // @@config@@ is a macro
    let config = JSON.parse(decodeURIComponent(escape(window.atob('@@config@@'))));
</script>
<body>
 ... nuxt generated body ...
</body>

本质上,当我运行命令YARN生成时,我想要一个特定的页面(pages/login/index.html)以具有此特定标签的存在,并且在期间不注射Vue的生命周期。还有其他解决方案,例如让脚本自动后处理静态页面输出,但是我希望有一种方法可以在没有这种并发症的情况下完成此操作。

我的nuxt版本是2.15.8

In examples like this we have the v-html directive to dynamically render the raw html into the dom. I am in need of a way to insert a raw script before the entire lifecycle begins its magic. This is because I am working with a macro (auth0).

<!doctype html>
<html lang="en" data-n-head="...">
<head>...nuxt generated head...</head>
<script>
    // this tag needs to exist as html when building with 'yarn generate'
    // @@config@@ is a macro
    let config = JSON.parse(decodeURIComponent(escape(window.atob('@@config@@'))));
</script>
<body>
 ... nuxt generated body ...
</body>

In essence, when I run the command yarn generate I would like a specific page (pages/login/index.html) to have this specific tag to exist and not injected during vue's lifecycle. There are alternate solutions like having scripts automatically postprocessing the static page output, but I'm hoping that there is a way to accomplish this without such complications.

My nuxt version is 2.15.8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文