useRouteAnnouncer v3.12

源码
此 composable 会观察页面标题的变化,并相应地更新播报消息。
此 composable 在 Nuxt v3.12+ 中可用。

Description

A composable function used to watch for changes to the page title and update the announcer message accordingly. Used by <NuxtRouteAnnouncer> and can also be controlled manually.
It hooks into Unhead’s dom:rendered to read the page title and set it as the announcer message.

Nuxt 无障碍访问 中查看详情

参数

  • politeness: 设置屏幕阅读器播报的紧急程度:off(禁用播报)、polite(等待空闲)、或 assertive(立即打断)。 (默认 polite)。

属性

message

  • 类型: Ref<string>
  • 描述: 要播报的消息

politeness

  • 类型: Ref<string>
  • 描述: 屏幕阅读器播报紧急级别 offpoliteassertive

Methods

set(message, politeness = "polite")

Set the message to be announced and its urgency level.

polite(message)

Set the message with politeness = "polite".

assertive(message)

Set the message with politeness = "assertive".

示例

app/pages/index.vue
<script setup lang="ts">
const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
  politeness: 'assertive',
})
</script>
对于宣布页面内动态内容变化(表单验证、提示消息、加载状态),请改用 useAnnouncer