如何向Vue添加结构化数据(json-ld)?

Sam*_*her 5 structured-data json-ld vue.js

将json-ld添加到 vue 应用程序的正确方法是什么\xe2\x80\x99 ?

\n\n

我\xe2\x80\x99添加了一些结构化数据,但Google结构化数据测试工具未检测到我的网址上的数据。但是,如果我查看 url 的来源并将其粘贴到测试工具中,它会检测到我的数据。缺少什么?

\n

小智 1

使用 VueJS 添加 JSON-LD 的一种方法是使用v-html如下例所示。

您可以在本文中通过 VueJS 从 Schema.org 找到有关结构化数据的更多信息。

NPM 上还有这个插件可以帮助你做到这一点。

<script>
export default {
  data () {
    const jsonld = {
      "@context": "https://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "Books",
        "item": "https://example.com/books"
      }, {
        "@type": "ListItem",
        "position": 2,
        "name": "The Lord of the Rings",
        "item": "https://example.com/books/the-lord-of-the-rings"
      }]
    }
    return {
      jsonld
    }
  }
}
</script>
<template>
  <script v-html="jsonld", type="application/ld+json">
</template>
Run Code Online (Sandbox Code Playgroud)

  • Vue 不允许将 `&lt;script&gt;` 添加到模板`编译模板时出错:模板应该只负责将状态映射到 UI。避免在模板中放置具有副作用的标签,例如 &lt;style&gt;,因为它们不会被解析` (8认同)