"The :deep() selector in Vue3 is invalid when using the PrimeVue library"
P粉785522400
2023-08-29 23:45:06
<p>I am using vue3 and PrimeVue library. When I try to override the PrimeView component's css field using the <code>:deep()</code> selector, it has no effect. It only applies my changes when I use unscoped styles. I'm confused as to why it doesn't work. </p>
<p>Sample code with <code>:deep()</code>: </p>
<pre class="brush:js;toolbar:false;"><template>
<Toast position='buttom-right'/>
</template>
<style scoped>
:deep(.p-toast-message-icon) {
margin-right: 10px !important;
}
</style>
</pre>
<p>This doesn't work. </p>
<p>But when using <code>style</code> without scope, like this: </p>
<pre class="brush:js;toolbar:false;"><style>
.p-toast-message-icon {
margin-right: 10px !important;
}
</style>
</pre>
<p>That works. </p>
The rules generated through the
element, so the generated class will have no effect.:deep
selector will take effect for the child elements of the current component, butp-toast
is attached to theHowever, you can set pass options to pass style rules to the icon:
or
See examples in Sandbox.