Put in order · Vue.js course · Module 2: Template Syntax

Template Ref Lifecycle

Order the steps of using a template ref:

Items to put in order

  • onMounted: the element is available
  • Template: ref="inputRef" on the element
  • Declaration: const inputRef = ref(null)
  • Usage: inputRef.value?.focus()
Show the answer

Correct order:

  1. Declaration: const inputRef = ref(null)
  2. Template: ref="inputRef" on the element
  3. onMounted: the element is available
  4. Usage: inputRef.value?.focus()