The useId()
composable returns a Vue Ref holding a string that can be used as a unique identifier to apply to a DOM node attribute.
Should you supply a function (getValue
from the typing below) to get the value that the id might have, it will make sure to keep it updated.
On SSR, it takes into account the process of hydration so that your component won’t generate any such errors.
語法
import { useId } from 'quasar'
setup () {
const id = useId()
// ...
}
content_paste
function useId(
opts?: {
getValue?: () => string | null | undefined;
required?: boolean; // default: true
}
): Ref<string | null>;
content_paste
範例
<template>
<div :id="id">
Some component
</div>
</template>
<script>
import { useId } from 'quasar'
export default {
props: {
for: String
},
setup () {
const id = useId({
getValue: () => props.for,
required: true
})
return { id }
}
}
</script>
content_paste