Deepening our knowledge of props
In Chapter 3, we introduced and started to use properties as a way to pass information from a component to its children. As our understanding of Vue.js is widening, it is time to expand our knowledge of this basic feature.
Just as a quick recap, so far, we have learned that properties (props) are defined using the defineProps
compiler macro, like so:
const props = defineProps({ name: String });
Doing so will allow our component to accept a prop called name
of type String
:
<myComponent :name="myName" />
In this section, we are going to learn what other configurations properties have to offer. The ability to define a props type is not the only configuration available.
Props configurations
In most cases, just configuring a prop type, as previously shown, is more than enough, but there are times when fine control is needed, and the following configuration will help you.
The syntax we used to declare properties...