"The :deep() selector in Vue3 is invalid when using the PrimeVue library"
P粉785522400
P粉785522400 2023-08-29 23:45:06
0
1
541
<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>
P粉785522400
P粉785522400

reply all(1)
P粉094351878

The rules generated through the :deep selector will take effect for the child elements of the current component, but p-toast is attached to the

element, so the generated class will have no effect.

However, you can set pass options to pass style rules to the icon:

<Toast
    :pt="{
        icon: { style: 'marginRight: 10px !important;' }
    }"
/>

or

<Toast
    :pt="{
        icon: { class: 'mr-2' }
    }"
/>

See examples in Sandbox.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!