vue prop function code example
Example 1: vue js default prop
props: {
name: {
type: String,
default: 'John Doe'
}
}
Example 2: vue prop string or number
props: {
users_count: {
type: [Number, String],
required: true
}
},
Example 3: pass method as props vue
//You should probably not pass methods as props in Vue, instead, emit an event.
//In parent component, do for example:
methods: {
sayHi() {
alert('Hi')
}
}
// In child component, do:
methods: {
doSomething() {
this.$emit('alert')
}
}