Setting inheritAttrs=false breaks scoped style
Version
3.2.26
Reproduction link
Steps to reproduce
AttrsComp.vue
: setinheritAttrs=false
, pass attrs to child<img v-bind="$attrs">
.App.vue
: render<AttrsComp class="test" />
, where.test { width: 90vw }
is defined in<style scoped>
What is expected?
- attrs pass to child:
<img class="test">
- child
<img >
rendered with 90vw width
What is actually happening?
- attrs pass to child:
<img class="test">
✅ - child
<img>
rendered with default width ❌
Use case:
AttrsComp.vue
was once single<img>
, inheriting scoped class fromApp.vue
.- With feature changes,
AttrsComp.vue
refactored into<picture>
, all attrs should be passed into child<img>
Due to this issue, all classes passed into <AttrsComp>
must be moved to non-scoped, which breaks component encapsulation.
I'd not rate this a bug as the SFC spec explicitly states that the style scoping only extends to the root element of a child component, but I see a use in discussing how to enhance the behaviour for this specific usecase
In the meantime, we have :deep()
to extend styles to deeply nested elements as well as css modules as usable alternatives.
@LinusBorg
Noted.
Maybe css-modules fit this use case better, but the Vue community invested in scoped styles, so...