Skip to content

Instantly share code, notes, and snippets.

@opejovic
Last active September 13, 2020 08:18
Show Gist options
  • Save opejovic/2bc1c71b28237eb33310c06c813a54a5 to your computer and use it in GitHub Desktop.
Save opejovic/2bc1c71b28237eb33310c06c813a54a5 to your computer and use it in GitHub Desktop.
How ti install Vue in new Laravel 8 application
  1. run npm install --save vue

  2. Add the following to your resources/js/app.js:

     window.Vue = require('vue');
     Vue.component('example-component', require('./components/ExampleComponent.vue').default);
     const app = new Vue({
       el: '#app',
     });
    
  3. Create an ExampleComponent.vue in the resources/js/components directory

    <template>
      <div>Hello World.</div>
    </template>
    
    <script>
      export default {
        mounted() {
          console.log("Example component mounted");
        }
      };
    </script>
    
  4. Add <script src="{{ asset('js/app.js') }}" defer></script> in the <head> section of your layout file (resources/views/layouts/app.blade.php)

  5. Add id="app" to <body> or main <div> in your layout file (resources/views/layouts/app.blade.php)

  6. Add <example-component /> to your view

  7. Run npm run dev or npm run watch

  8. Finally, open up the devtools, and in the console log you should see Example component mounted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment