Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Full-Stack Vue.js 2 and Laravel 5

You're reading from   Full-Stack Vue.js 2 and Laravel 5 Bring the frontend and backend together with Vue, Vuex, and Laravel

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788299589
Length 376 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Anthony Gore Anthony Gore
Author Profile Icon Anthony Gore
Anthony Gore
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Hello Vue – An Introduction to Vue.js FREE CHAPTER 2. Prototyping Vuebnb, Your First Vue.js Project 3. Setting Up a Laravel Development Environment 4. Building a Web Service with Laravel 5. Integrating Laravel and Vue.js with Webpack 6. Composing Widgets with Vue.js Components 7. Building a Multi-Page App with Vue Router 8. Managing Your Application State with Vuex 9. Adding a User Login and API Authentication with Passport 10. Deploying a Full-Stack App to the Cloud

Communicating with components


A key aspect of components is that they are reusable, which is why we give them their own state to keep them independent from the rest of the app. However, we may still want to send in data, or send it out. Components have an interface for communicating with other parts of the app, which we will now explore.

Props

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime