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.

JavaScript<br />

JavaScript assets are kept in the resources/assets/<strong>js</strong> folder. There are several .<strong>js</strong><br />

files in this directory, as well as a sub-directory component, with a .vue file. This<br />

latter file will be explained in another chapter so we'll ignore it for now.<br />

The main JavaScript file is app.<strong>js</strong>. You'll see the familiar <strong>Vue</strong> constructor in this<br />

file, but also some syntax that may not be as familiar. On the first line is a require<br />

function that is intended to import an adjacent file, bootstrap.<strong>js</strong>, which in turn<br />

loads other libraries including jQuery <strong>and</strong> Lodash.<br />

require is not a st<strong>and</strong>ard JavaScript function <strong>and</strong> must be resolved somehow<br />

before this code can be used in a browser.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: require('./bootstrap'); window.<strong>Vue</strong> = require('vue');<br />

<strong>Vue</strong>.component('example', require('./components/Example.vue')); const app =<br />

new <strong>Vue</strong>({ el: '#app' });

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

Saved successfully!

Ooh no, something went wrong!