Nuxt 中使用 useHead 优化 SEO 与 GEO

本文介绍如何在 Nuxt 中使用 useHead 设置规范链接和 JSON-LD 结构化数据,帮助搜索引擎及 AI 更准确地理解页面内容,从而提升页面的 SEO 与 GEO 基础表现。

一、什么是 SEO 与 GEO

SEO 是搜索引擎优化,目的是让网页更容易被搜索引擎抓取、理解和展示。

GEO 可以理解为生成式引擎优化,重点是让 ChatGPT、Google AI 等生成式搜索工具更容易理解和引用网页内容。

在 Nuxt 中,可以使用 useHead 动态设置页面的 <head> 信息,例如:

php 复制代码
useHead({
  link: [
    {
      rel: 'canonical',
      href: url,
    },
  ],
  script: [
    {
      type: 'application/ld+json',
      innerHTML: JSON.stringify({
        '@context': 'https://schema.org',
        '@type': 'Article',
        headline: title,
        description,
        mainEntityOfPage: url,
      }),
    },
  ],
})

二、为什么需要设置 canonical

canonical 用于告诉搜索引擎当前页面的规范 URL。

例如,同一篇文章可能通过以下地址访问:

bash 复制代码
https://example.com/article/1
https://example.com/article/1?source=google
https://example.com/article/1?utm_campaign=test

这些地址内容相同,但 URL 不同。通过设置:

css 复制代码
{
  rel: 'canonical',
  href: 'https://example.com/article/1',
}

可以告诉搜索引擎:

https://example.com/article/1 才是这篇内容的正式地址。

这样可以减少重复内容问题,避免页面权重被不同 URL 分散。

三、什么是 JSON-LD 结构化数据

JSON-LD 是一种结构化数据格式,常用于向搜索引擎说明网页的类型和内容。

例如,可以告诉搜索引擎:

  • 这是一个文章页面
  • 文章标题是什么
  • 文章描述是什么
  • 作者是谁
  • 发布时间是什么
  • 页面主地址是什么

在 Nuxt 中,可以通过以下方式添加:

css 复制代码
{
  type: 'application/ld+json',
  innerHTML: JSON.stringify({
    '@context': 'https://schema.org',
    '@type': 'Article',
    headline: title,
    description,
    mainEntityOfPage: url,
  }),
}

四、每个字段的作用

1. @context

less 复制代码
'@context': 'https://schema.org'

表示使用 Schema.org 标准描述页面内容,通常固定填写,不需要修改。

2. @type

arduino 复制代码
'@type': 'Article'

表示页面类型是文章。

根据页面内容,也可以使用:

arduino 复制代码
'@type': 'BlogPosting'

适合博客文章;或者:

arduino 复制代码
'@type': 'NewsArticle'

适合新闻内容。

3. headline

makefile 复制代码
headline: title

表示文章标题,例如:

vbnet 复制代码
headline: 'Nuxt 中如何使用 useHead 优化 SEO'

建议与页面上的主标题保持一致。

4. description

makefile 复制代码
description: description

表示文章摘要或页面描述,建议简洁说明文章主要内容。

例如:

vbnet 复制代码
description: '本文介绍如何在 Nuxt 中使用 useHead 设置 canonical 和 JSON-LD 结构化数据。'

5. mainEntityOfPage

makefile 复制代码
mainEntityOfPage: url

表示这篇文章对应的主要页面 URL。

例如:

rust 复制代码
mainEntityOfPage: 'https://example.com/articles/nuxt-seo'

建议使用完整的绝对 URL,而不是相对路径。

五、推荐添加的字段

除了基础字段,还可以添加图片、作者、发布者和时间信息:

php 复制代码
useHead({
  link: [
    {
      rel: 'canonical',
      href: url,
    },
  ],
  script: [
    {
      type: 'application/ld+json',
      innerHTML: JSON.stringify({
        '@context': 'https://schema.org',
        '@type': 'Article',
        headline: title,
        description,
        image: imageUrl,
        author: {
          '@type': 'Person',
          name: authorName,
        },
        publisher: {
          '@type': 'Organization',
          name: siteName,
          logo: {
            '@type': 'ImageObject',
            url: logoUrl,
          },
        },
        datePublished: publishedAt,
        dateModified: updatedAt,
        mainEntityOfPage: {
          '@type': 'WebPage',
          '@id': url,
        },
      }),
    },
  ],
})

字段说明:

  • image:文章主图的完整 URL
  • author:作者信息
  • publisher:发布网站或机构
  • logo:网站或机构的 Logo
  • datePublished:文章首次发布时间
  • dateModified:文章最后更新时间
  • mainEntityOfPage:文章所属的主要网页

时间建议使用 ISO 8601 格式,例如:

makefile 复制代码
2025-01-01T08:00:00Z

六、Nuxt 中的完整示例

php 复制代码
<script setup lang="ts">
const title = 'Nuxt 中如何使用 useHead 优化 SEO'
const description = '本文介绍如何在 Nuxt 中使用 useHead 设置 canonical 和 JSON-LD 结构化数据。'
const url = 'https://example.com/articles/nuxt-seo'
const imageUrl = 'https://example.com/images/nuxt-seo.jpg'
const authorName = '张三'
const siteName = '示例网站'
const logoUrl = 'https://example.com/logo.png'
const publishedAt = '2025-01-01T08:00:00Z'
const updatedAt = '2025-01-02T08:00:00Z'

useHead({
  link: [
    {
      rel: 'canonical',
      href: url,
    },
  ],
  script: [
    {
      type: 'application/ld+json',
      innerHTML: JSON.stringify({
        '@context': 'https://schema.org',
        '@type': 'Article',
        headline: title,
        description,
        image: imageUrl,
        author: {
          '@type': 'Person',
          name: authorName,
        },
        publisher: {
          '@type': 'Organization',
          name: siteName,
          logo: {
            '@type': 'ImageObject',
            url: logoUrl,
          },
        },
        datePublished: publishedAt,
        dateModified: updatedAt,
        mainEntityOfPage: {
          '@type': 'WebPage',
          '@id': url,
        },
      }),
    },
  ],
})
</script>

七、使用时的注意事项

首先,所有 URL 最好使用完整地址,例如:

arduino 复制代码
https://example.com/article/1

不要只使用:

bash 复制代码
/article/1

其次,结构化数据中的标题、描述、作者和日期应与页面实际内容保持一致,不能填写虚假信息。

另外,不同页面应根据实际类型选择合适的 @type。产品页、FAQ 页、面包屑页面等,不一定都应该使用 Article。

最后,结构化数据只是 SEO 和 GEO 的基础优化,不能保证一定提升排名或被 AI 引用。页面本身还需要具备真实、有价值、结构清晰且可抓取的内容。

相关推荐
徐小夕4 小时前
万字分享:CRDT 算法在 Word 文档中的工程化落地
前端·vue.js·github
king王一帅4 小时前
啃完几十份国标,QuireKit 实现了像 Word 一样流畅的浏览器 OFD 编辑器,支持完备电子签标准与 OFD-H
前端·typescript·产品
菩提树下的凡夫4 小时前
Web前端常见问题及解答
前端
map_3d_vis5 小时前
百度地图添加标注 Marker 和自定义图标(JSAPI 4.0)
前端·javascript·地图·百度地图
码云数智-园园5 小时前
HTML5 FileReader 读取本地文件,前端上传预览原理
前端·html·html5
恋猫de小郭5 小时前
Flutter Analyzer ,这玩意还有这么大的优化空间
android·前端·flutter
honkun65 小时前
vue 表格组件 vxe-table 行拖拽排序时,为“拖拽为子级”增加操作提示
前端·javascript·vue.js·vxe-table
qinqinzqq5 小时前
CSS Grid 命名区域布局:组件 Header / Content / Sider 两栏布局实践
前端·css
子非鱼a6 小时前
【WEB】[NewStarCTF 公开赛赛道]IncludeOne
前端·php
油丶酸萝卜别吃6 小时前
Vue2 实现全局主题切换功能:CSS Variables + Vuex
开发语言·前端·javascript