Skip to content

useTemplateRef() can not get the element, the value will be null #13266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DiHaozhe-365 opened this issue May 1, 2025 · 0 comments
Closed

useTemplateRef() can not get the element, the value will be null #13266

DiHaozhe-365 opened this issue May 1, 2025 · 0 comments

Comments

@DiHaozhe-365
Copy link

Vue version

3.5.13

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk2L2zAQ/SuDLkkgtQlpL4uz0JY9tNAPtktPgqIqY1tbeWT04QZC/ntHSp12lyU36c3ozXtvdBRvx7GaEoob0QTtzRghYEwjWEXdTooYpLiVZIbR+QhHcPTJJYq4X0MK+IDDaFXEe2zhBK13AyyYbCFJ0qVzuVzB7haOkgC0oxAhmmgRds8YlouCL1Zzo7NYWdctC1xNyiZcQV0DJWtzj2nhaa2MuP5WKwJyEZTWGALE3gSwhjC/PEk68fCmPgfBtvkS/wrkG0CzNxNoq0LgaHr07tVPRYS+ZJRHN/0GPLY5uDyY8e8Jt9Wbpu43Z4aaKfjU1BdiseaUWXNruuoxOOJVFCNSaDeMxqL/MkbDnqS4mS1Koax1vz8WLPqE6xnXPepfL+CP4ZAxKb56DOgn1napReU7jOfy3bfPeODzpTi4fcpOrhTvkfNOWeO57V2iPcv+r6+o/VA+kaHuIdwdIlKYTWWhZQGlXwr+Qu+vWP8nd1u9nhfHKf6Y0GdODpAjrzZbcfoD2BTz6Q==

Steps to reproduce

<script setup lang="ts">
import { onMounted, useTemplateRef } from 'vue'

onMounted(() => {
  const title = useTemplateRef('title')
  console.log(title.value) // null
  if (title.value) {
    console.log(title.value) // can not access this line
  }
})
</script>

<template>
  <div>
    <h1 ref="title">Vue3.5</h1>
  </div>
</template>

What is expected?

What is actually happening?

System Info

Any additional comments?

No response

@DiHaozhe-365 DiHaozhe-365 changed the title useTemplateRef() can not get the element useTemplateRef() can not get the element, the value will be null May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant