Standard example of component in Vue looks like that:
Vue.component('blog-post', {
// camelCase in JavaScript
props: ['postTitle'],
template: '<h3>{{ postTitle }}</h3>'
})
In basic docs about components there's no data object used, just props. However documentation of data mentions components:
Restriction: Only accepts Function when used in a component definition.
There's even example:
var data = { a: 1 }
// direct instance creation
var vm = new Vue({
data: data
})
vm.a // => 1
vm.$data === data // => true
// must use function when in Vue.extend()
var Component = Vue.extend({
data: function () {
return { a: 1 }
}
})
Does it mean that component can have both data and props? Is data kind of private property (if we'd like to compare to OOP) and property public one?
props
are received by the parent component whiledata
are manipulated by the component. Theprops
are static (changeable by the parent) whiledata
are dynamic (but cannot be changed by the parent). – Karl-André Gagnonarray or object
, they don't show that console error ! For string type of prop , I use$emit
!! – David Jaw Hpan