vuejs @Prop code example
Example 1: vue js default prop
props: {
name: {
type: String,
default: 'John Doe'
}
}
Example 2: vuejs props
// Component file
<script>
export default {
props: {
name: {
type: String,
required: true
}
}
};
</script>
// File you call your component
<template>
<your-component name="name"></your-component>
</template>
Example 3: vue prop string or number
props: {
users_count: {
type: [Number, String],
required: true
}
},
Example 4: vue js props
Vue.component('blog-post', {
// camelCase in JavaScript
props: ['postTitle'],
template: '<h3>{{ postTitle }}</h3>'
})
<blog-post post-title="hello!"></blog-post>
Example 5: vuejs components props pass array
<blog-post v-bind:comment-ids="[234, 266, 273]"></blog-post>
<blog-post v-bind:comment-ids="post.commentIds"></blog-post>