Vue · Middle · Question 12 of 75

How do you apply fallthrough attributes to an inner element instead of the root?

<script setup>
defineOptions({ inheritAttrs: false });
</script>
<template>
  <label class="field"><input v-bind="$attrs" /></label>
</template>

Explanation

This is common for wrapped inputs: placeholder, aria-* and @input should reach the <input>, not the wrapper. Components with multiple roots must bind $attrs explicitly.

Further reading

Problem with a question

Vue · Middle · question 12

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz