【问题标题】:how to include json-ld script in nuxt 3?如何在 nuxt 3 中包含 json-ld 脚本?
【发布时间】:2021-12-22 06:08:21
【问题描述】:

我正在尝试将 json-ld 添加到我的页面,但仍然无法正常工作或不是我想要的。

这是我迄今为止尝试过的:

  1. 使用 useMeta()
useMeta({
    script: [
        {
            type: 'application/ld-json',
            json: jsonLd,
        },
    ],
});

结果:<script type="application/ld-json" json="[object Object]"></script>

  1. 使用<Script>标签
<Script type="application/ld-json">
        {{ jsonLd }}
</Script>

结果:&lt;script type="application/ld+json"&gt;&lt;/script&gt; 空值。

<Script type="application/ld-json" v-html="jsonLd"></Script>

结果:&lt;script type="application/ld-json" innerhtml="[object Object]"&gt;&lt;/script&gt;

我错过了什么吗? 谢谢。

【问题讨论】:

    标签: json vue.js nuxt3


    【解决方案1】:

    如果有人想知道,这就是我的工作方式:

    使用

    &lt;Script :children="jsonLd" /&gt;

    或者

    useMeta({
        script: [
            {
                type: 'application/ld-json',
                children: JSON.stringify(jsonLd),
            },
        ],
    });
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2023-02-16
        • 1970-01-01
        • 2021-09-17
        • 2020-06-05
        • 2015-01-09
        • 2021-01-21
        • 2018-02-24
        • 2016-05-21
        • 1970-01-01
        相关资源
        最近更新 更多