Answer the question
In order to leave comments, you need to log in
How to pass style from parent component to child?
Hello, in the styles of the parent component there is
.wrapper{
$gap: 10vmin;
}
Answer the question
In order to leave comments, you need to log in
No. Use custom properties.
.wrapper {
--gap: 10vmin;
}
.children {
margin: var(--gap);
}
<div class="wrapper">
<div class="children">
<!-- Применится margin: 10vmin -->
</div>
</div>
1. Any common css can only be used if the child components cannot exist without the parent component. In this case, allocate a separate folder for such a bunch of components, make a file there <compnent-group-name>.variables.scss
and import it where necessary.
2. If these components are not connected, any things that control and change the behavior of the component must be passed exclusively through props
. Each individual component is a black box. You should be able to completely and drastically change the layout inside a component without changing its behavior. In vue 3, there is even a handy construct for this v-bind
inside <style>
.
PS Well, of course, if this is a $gap
global parameter, you canconfig vue\sass-loader add a file with variables common to all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question