useRouteAnnouncer

此可组合函数会观察页面标题的变化并相应地更新播音员消息。
此可组合项在 Nuxt v3.12+ 版本中可用。

描述

¥Description

一个可组合项,用于观察页面标题的变化并相应地更新播音员消息。由 <NuxtRouteAnnouncer> 使用且可控。它连接到 Unhead 的 dom:rendered 以读取页面标题并将其设置为公告消息。

¥A composable which observes the page title changes and updates the announcer message accordingly. Used by <NuxtRouteAnnouncer> and controllable. It hooks into Unhead's dom:rendered to read the page's title and set it as the announcer message.

参数

¥Parameters

  • politeness:设置屏幕阅读器公告的紧急程度:off(禁用通知)、polite(等待静音)或 assertive(立即中断)。(默认 polite)。

属性

¥Properties

message

  • 类型:Ref<string>
  • 说明:要显示的消息

politeness

  • 类型:Ref<string>
  • 说明:屏幕阅读器公告紧急程度 offpoliteassertive

方法

¥Methods

set(message, politeness = "polite")

设置要宣布的消息及其紧急程度。

¥Sets the message to announce with its urgency level.

polite(message)

使用 politeness = "polite" 设置消息

¥Sets the message with politeness = "polite"

assertive(message)

使用 politeness = "assertive" 设置消息

¥Sets the message with politeness = "assertive"

示例

¥Example

pages/index.vue
<script setup lang="ts">
  const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
    politeness: 'assertive'
  })
</script>