Scoped styles not being applied to child elements in render functions
Vue version
3.3.4
Link to minimal reproduction
Steps to reproduce
- Inside a render function, create an element with a child element.
- Set the
scoped
attribute on the style tag. - Add styles for the child element using any selector.
What is expected?
The 'nested' p
tag should be blue
What is actually happening?
The nested p
tag is red.
System Info
No response
Any additional comments?
Related issue: https://github.com/vuejs/core/issues/1539
@davidleger95 According to me it is working fine.
To check this I have simplified your example Link: Simplified Version Preview:
Note: Your style section of the component
<style scoped>
p {
color: blue;
}
</style>
Gets Converted to
p[data-v-472cff63] {
color: blue;
}
Actually rendered is something like this
Note: P tag does not have data-* attribute so CSS style will not get applied here.
If you want to apply some CSS to child components you need to use :deep
Ref: https://vuejs.org/api/sfc-css-features.html#scoped-css
:deep(p) { // this way you can style child elements
color: blue;
}