25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Virtual DOM<br />

Let's change tack now <strong>and</strong> discuss how <strong>Vue</strong> renders components. Take a look at<br />

this example: <strong>Vue</strong>.component('my-component', { template: 'My<br />

component' });<br />

In order for <strong>Vue</strong> to be able to render this component to the page, it will first<br />

transform the template string into a JavaScript object using an internal template<br />

compiler library:<br />

Figure 6.14. How the template compiler turns a template string into an object Once the template has been<br />

compiled, any state or directives can easily be applied. For example, if the template includes a v-for, a<br />

simple for-loop can be used to multiply the nodes <strong>and</strong> interpolate the correct variables.<br />

After that, <strong>Vue</strong> can interface with the DOM API to synchronize the page with the<br />

state of the component.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!