Skip to content
Advertisement

Check if props in vue.js component template exists

After tried many variations, I don’t know how to properly style a component’s slot or partial code within <template></template> section.

Is there a way to check if props <counter :recent="true"></counter> from parent level exists, so in a Counter.vue in section <template></template> i would show a special html markup for it ?

=== UPDATED ===

JavaScript
JavaScript

Advertisement

Answer

Here the default value for the recent will be false and if the recent is passed from the parent it will get set in the child.

Just use the detailed props definition as mentioned here.

Remove the v-text="number" as it overrides the internal content of the span and therefore the v-if will never executes.

This is a working example

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement