You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A component non-prop attribute is an attribute or event listener that is passed to a component, but does not have a corresponding property defined in [props](component-props) or [emits](component-custom-events.html#defining-custom-events). Common examples of this include `class`, `style`, and `id` attributes.
When a component returns a single root node, non-prop attributes will automatically be added to the root node's attributes. For example, in the instance of a date-picker component:
In the event we need to define the status of the date-picker component via a `data-status`property, it will be applied to the root node (i.e.,`div.date-picker`).
In this case, `change`event listener is passed from the parent component to the child and it will be triggered on native `<select>``change`event. We won't need to emit an event from the `date-picker`explicitly:
By setting the `inheritAttrs` option to `false`, this gives you access to the component's `$attrs` property, which includes all attributes not included to component `props` and `emits` properties (e.g., `class`, `style`, `v-on` listeners, etc.).
Using our date-picker component example from the [previous section]('#attribute-inheritance), in the event we need to apply all non-prop attributes to the `input` element rather than the root `div` element, this can be accomplished by using the `v-bind` shortcut.
With this new configuration, our `data-status`attribute will be applied to our `input`element!
103
+
このように記述した場合、`data-status`属性は、 `input`要素に適用されます。
101
104
102
105
```html
103
106
<!-- Date-picker component with a non-prop attribute -->
@@ -111,14 +114,14 @@ With this new configuration, our `data-status` attribute will be applied to our
111
114
112
115
## Attribute Inheritance on Multiple Root Nodes
113
116
114
-
Unlike single root node components, components with multiple root nodes do not have an automatic attribute fallthrough behavior. If `$attrs`are not bound explicitly, a runtime warning will be issued.
0 commit comments