Reputation: 203
my Vue
project use Vue.Router.
i want to apply css style for child components from parent. but, i defined css style in parent, it is not applied in child components. and my stylesheet use same class or id selector.
like blow:
list-one.css
.foo bar {
width: 120px;
}
not-related-for-list-one.css
.foo bar {
width: 200px;
}
two example css file use seperate different Vue components(ListOne.vue
, NotForListOne.vue
)
in parent(Vue components, ListOne.vue
), i define css style several ways, like below:
<style src="my/css/file/path/list-one.css" scope>
<script>import "my/css/file/path/list-one.css"</script>
<style scope>my css style here</style>
'1' is applied only parent component(
ListOne.vue
).'2' is applied global(
list-one.css
andnot-related-for-list- one.css
both appliedListOne.vue
) becauseNotForListOne.vue
has<script>import "my/css/file/path/not-related-for-list-one.css"</script>
.'3' is same '1'.
ListOne.vue
<child-one></child-one>
<child-two></child-two>
<and-other-childs></and-other-childs>
list-one.css
/* it for ListOne.vue only */
.foo bar {
width: 120px;
}
/* it for chile-one only */
.foo1 bar {
display: none;
}
/* it for chile-two only */
.foo2 bar {
color: red;
}
.
.
.
I think most better ways is this:
ListOne.vue
....
<style>
.foo bar {
width: 120px;
}
</style>
ChildOne.vue
<style>
.foo1 bar {
display: none;
}
</style>
ChildTwo.vue
<style>
.foo2 bar {
color: red;
}
</style>
but css file is so big, it is so hard to split css for its Vue components.
how to solve this?
Upvotes: 0
Views: 5798
Reputation: 1232
<style scope>my css style here</style>
try to remove the scope
from style
tag.
Upvotes: 2