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.

Syntax clash<br />

Using the prototype template file as a view will cause a small issue as <strong>Vue</strong> <strong>and</strong><br />

Blade share a common syntax. For example, look at the heading section where<br />

<strong>Vue</strong>.<strong>js</strong> interpolates the title <strong>and</strong> address of a listing.<br />

resources/views/app.blade.php: {{ title }} {{<br />

address }} <br />

When Blade processes this, it will think the double curly brackets are its own<br />

syntax <strong>and</strong> will generate a PHP error as neither title nor address are defined<br />

functions.<br />

There is a simple solution: escape these double curly brackets to let Blade know<br />

to ignore them. This can be done by placing an @ symbol as a prefix.<br />

resources/views/app.blade.php: @{{ title }}<br />

@{{ address }} <br />

Once you've done that for each set of double curly brackets in the file, load the<br />

home route in the browser to test the new view. Without the JavaScript or CSS it<br />

doesn't look great, but at least we can confirm it works:

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

Saved successfully!

Ooh no, something went wrong!