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.
参数
politeness: 设置屏幕阅读器播报的紧急程度:off(禁用播报)、polite(等待空闲)、或assertive(立即打断)。 (默认polite)。
属性
message
- 类型:
Ref<string> - 描述: 要播报的消息
politeness
- 类型:
Ref<string> - 描述: 屏幕阅读器播报紧急级别
off、polite或assertive
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。