Skip to content

templateRef

Category
Export Size
283 B
Last Changed
6 months ago

Shorthand for binding ref to template element.

Usage

vue
<script lang="ts">
import { templateRef } from '@vueuse/core'

export default {
  setup() {
    const target = templateRef('target')

    // no need to return the `target`, it will bind to the ref magically
  },
}
</script>

<template>
  <div ref="target" />
</template>

With JSX/TSX

tsx
import { templateRef } from '@vueuse/core'

export default {
  setup() {
    const target = templateRef<HTMLElement | null>('target', null)

    // use string ref
    return () => <div ref="target"></div>
  },
}

<script setup>
Talks: June 3-4 Live Coding: June 5th
Join for Free ➜
05
days
:
14
hours
:
48
minutes
:
22
seconds
: