If you want to sprinkle some vuejs in your files with blades, you have basically two options:
Option number 1
Declare Vue Global Components
Example
// in laravel built in app.js file Vue.component('foo', require('./components/Foo.vue')); Vue.component('bar', require('./components/Bar.vue')); const app = new Vue({ el: '#app' });
create the main layout file where the root div has the identifier #app
// layout.blade.php <html> <header></header> <body> <div id="app"> @yield('content') </div> </body> </html>
Finally, in your views:
//some-view.blade.php @extends('layout') @section('content') <foo :prop="{{ $someVarFromController }}"></foo> @endsection
Option number 2
This is what I am using now, and gives me a lot of flexibility actually
// in laravel built in app.js file const app = new Vue({ el: '#app', components: { Foo: require('./components/Foo.vue'), Bar: require('./components/Bar.vue') } });
In the layout file you will use vuejs dynamic components
<html> <header></header> <body> <div id="app"> @if (isset($component)) <component :is={{ $component }} inline-template> @endif @yield('content') @if (isset($component)) </component> @endif </div> </body> </html>
In your views:
//some-view.blade.php @extends('layout', ['component' => 'foo']) @section('content') // all the vue stuff available in blade // don't forget to use the @ symbol every time you don't want blade to parse the expression. // Example: @{{ some.vue.propertie }} @endsection
And finally, you can create vue components, as always,
// resources/assets/js/components/foo.vue <script> export default { </script>