How to correctly use “scoped” styles in VueJS single file components?

前端 未结 1 734
难免孤独
难免孤独 2020-11-30 09:57

The docs on VueJS state that scoped should limit styles to the component. But if I create 2 components with same baz style, it will leak from one c

相关标签:
1条回答
  • 2020-11-30 10:23

    You can read on the Vue loader's docs:

    A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.

    This is apparently what it is meant to do, even though it might seem a bit confusing.

    If you want to avoid that, you should use css modules:

    <template>
    <div :class="$style.baz">
      <Bar></Bar>
    </div>
    </template>
    
    <style module>
    .baz {
      color: red;
    }
    </style>
    
    0 讨论(0)
提交回复
热议问题