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
Copy file name to clipboardExpand all lines: src/guide/class-and-style.md
+22-5Lines changed: 22 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -123,9 +123,7 @@ However, this can be a bit verbose if you have multiple conditional classes. Tha
123
123
124
124
> This section assumes knowledge of [Vue Components](component-basics.md). Feel free to skip it and come back later.
125
125
126
-
> TODO: revise this with multi-root components
127
-
128
-
When you use the `class` attribute on a custom component, those classes will be added to the component's root element. Existing classes on this element will not be overwritten.
126
+
When you use the `class` attribute on a custom component with a single root element, those classes will be added to this element. Existing classes on this element will not be overwritten.
129
127
130
128
For example, if you declare this component:
131
129
@@ -151,8 +149,6 @@ The rendered HTML will be:
151
149
<pclass="foo bar baz boo">Hi</p>
152
150
```
153
151
154
-
> TODO: needs a check after https://github.com/vuejs/rfcs/blob/attr-fallthrough/active-rfcs/0000-attr-fallthrough.md is merged
155
-
156
152
The same is true for class bindings:
157
153
158
154
```html
@@ -165,6 +161,27 @@ When `isActive` is truthy, the rendered HTML will be:
165
161
<pclass="foo bar active">Hi</p>
166
162
```
167
163
164
+
If your component has multiple root elements, you would need to define which component will receive this class. You can do this using `$attrs` component property:
165
+
166
+
```html
167
+
<divid="app">
168
+
<my-componentclass="baz"></my-component>
169
+
</div>
170
+
```
171
+
172
+
```js
173
+
constapp=Vue.createApp()
174
+
175
+
app.component('my-component', {
176
+
template:`
177
+
<p :class="$attrs.class">Hi!</p>
178
+
<span>This is a child component</span>
179
+
`
180
+
})
181
+
```
182
+
183
+
You can learn more about component attribute inheritance in [Component Props](component-props.html#non-prop-attributes) section
0 commit comments