Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

vue3 inheritAttrs Property

Vue3 inheritAttrs Property


Vue3 Options API Vue3 Options API

In Vue 3,inheritAttrs is a component option that determines whether non-prop attributes (i.e., attributes not explicitly defined as props) passed from the parent component to the child component should be inherited onto the child component's root element.

By default,inheritAttrs has a value of true, which means all non-prop attributes passed by the parent component are automatically bound to the child component's root element. If you want to manually control the inheritance behavior of these attributes, you can set inheritAttrs to false.


How to Understand inheritAttrs?

Imagine you have a component MyButtonthat receives a label as a prop, and you want the parent component to be able to pass some extra attributes, such as class or style. By default, these extra attributes are bound directly to MyButton 's root element (usually a