mirror of https://github.com/vuejs/core.git
28 lines
709 B
TypeScript
28 lines
709 B
TypeScript
|
import {
|
||
|
type ComponentInternalInstance,
|
||
|
getCurrentInstance,
|
||
|
} from '../component'
|
||
|
import { warn } from '../warning'
|
||
|
|
||
|
export function useId() {
|
||
|
const i = getCurrentInstance()
|
||
|
if (i) {
|
||
|
return (i.appContext.config.idPrefix || 'v') + ':' + i.ids[0] + i.ids[1]++
|
||
|
} else if (__DEV__) {
|
||
|
warn(
|
||
|
`useId() is called when there is no active component ` +
|
||
|
`instance to be associated with.`,
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* There are 3 types of async boundaries:
|
||
|
* - async components
|
||
|
* - components with async setup()
|
||
|
* - components with serverPrefetch
|
||
|
*/
|
||
|
export function markAsyncBoundary(instance: ComponentInternalInstance) {
|
||
|
instance.ids = [instance.ids[0] + instance.ids[2]++ + '-', 0, 0]
|
||
|
}
|