mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 16:43:55 +00:00
658a0ffed7
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Sébastien Chopin <seb@nuxt.com>
30 lines
709 B
Markdown
30 lines
709 B
Markdown
---
|
|
title: "useId"
|
|
description: Generate an SSR-friendly unique identifier that can be passed to accessibility attributes.
|
|
---
|
|
|
|
`useId` generates an SSR-friendly unique identifier that can be passed to accessibility attributes.
|
|
|
|
Call `useId` at the top level of your component to generate a unique string identifier:
|
|
|
|
```vue [components/EmailField.vue]
|
|
<script setup lang="ts">
|
|
const id = useId()
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<label :for="id">Email</label>
|
|
<input :id="id" name="email" type="email"/>
|
|
</div>
|
|
</template>
|
|
```
|
|
|
|
## Parameters
|
|
|
|
`useId` does not take any parameters.
|
|
|
|
## Returns
|
|
|
|
`useId` returns a unique string associated with this particular `useId` call in this particular component.
|