Props Declaration

  • Using defineProps(): We can declare the props using defineprops() function
<script setup >
const student = defineProps([ 'name'] )
console.log(student.name )
</scirpt>
  • Using props option: We can define props using the props option:
export default {
props: [ 'name']
}
  • We can also use objects in place of an array to declare props
// In script setup 
defineProps({ name: String });

// In non scrpt setup
export default {
props: { name: String }
}
  • We can use TypeScript pure type annotations to declare props:
<script setup lang="ts">
defineProps<{
name ?: string
}>()
</script>

Refer to the Vue.js Props Declaration article for detailed description.

Vue.js Props

Vue.js Props is an attribute to the configuration of the component. It is used to pass the data to the component to work dynamically. The props configuration defines the type of data it can receive from different components of Vue.

Table of Content

  • Props Declaration
  • Prop Passing Details
  • One-Way Data Flow
  • Prop Validation
  • Boolean Casting

Similar Reads

Props Declaration

Using defineProps(): We can declare the props using defineprops() function...

Prop Passing Details

This facilitates the various components for the Props, such as Name Casing, Static vs. Dynamic Props, Passing Different Value Types, and Binding Multiple Properties Using an Object, which helps to manage & organize the Props in a structured manner in the Components....

One-Way Data Flow

In Vue.js, all the props are bonded between the child and properties are one-way-down. When we update the prop in the parent component it is updated to all the child components but the reverse does not happen and vue.js warns the use....

Prop Validation

Components can specify the criteria for their props, including their types. If these criteria are not met, Vue will issue a warning in the JavaScript console of the browser. This is typically valuable while generating the component meant for consumption by other developers....

Boolean Casting

Props with boolean type mimic the behavior of native boolean attributes....

Syntax

// Using script setup // Using non script setup