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
If you want to keep all the styling you've applied to a component but just switch out what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime. Another powerful feature of the `as` prop is that it preserves styles if the lowest-wrapped component is a `StyledComponent`.
245
+
246
+
**Example**
247
+
In `Component.js`
248
+
```js
249
+
// Renders a div element by default.
250
+
constComponent=styled('div', {})``
251
+
```
252
+
Using the `as` prop in another template/component would be as shown below.
253
+
```vue
254
+
<template>
255
+
<!-- Component will render a button instead of a div -->
256
+
<Component as="button" color="red">
257
+
Button
258
+
</Component>
259
+
</template>
260
+
```
261
+
This sort of thing is very useful in use cases like a navigation bar where some of the items should be links and some just buttons, but all be styled the same way.
262
+
243
263
### injectGlobal
244
264
245
265
A helper method to write global CSS. Does not return a component, adds the styles to the stylesheet directly.
0 commit comments