December 2017
Beginner to intermediate
376 pages
7h 53m
English
We can send data to a component through a custom HTML property know as a prop. We must also register this custom property in an array, props, in the component's configuration. In the following example, we've created a prop, title:
<div id="app"> <my-component title="My component!"></my-component> <!-- Renders as <div>My component!</div> --> </div> <script> Vue.component('my-component', { template: '<div>{{ title }}</div>', props: ['title'] }); new Vue({ el: '#app' }); </script>
A prop can be used just like any data property of the component: you can interpolate it in the template, use it in methods and computed properties, and so on. However, you should not mutate prop data. Think of prop data as being borrowed from another component ...
Read now
Unlock full access