Laravel: Using a mix between Blade and Vuejs - laravel

I'm developing a website using Laravel and I will need a mix between Blade templates and Vuejs components.
Basically the requirements of the project state that in the customer pages we can only use Blade but in the admin pages we are free to use anything, so we will use Blade + Vuejs.
I know is possible to create a form in Blade, and then require or #include that form in any other Blade file. Is it also possible require that form inside a Vuejs component?
For example, Is it possible to do something like this:
<my-form-component>
#include('path/to/blade/form')
</my-form-component>

If you want just use vue js in blade template, you can definetely use,
Hope you aware that blade and vue share similar syntax {{ }} for variable interpolation, to avoid vue and blade conflicting, you should add # notations ex: #{{ .. }} so blade engine will skip it,
But if you want to use vuejs component and blade template mixing, you shouldnot do it..

Related

How to Use Vuejs on Laravel blade

everyone, I want to make a dormitory management system with laravel and vuejs but I don't know how to display my data instead of "welcome.blade.php" file but instead of "blade" use vue component if someone knows this please help me how to do this. I use API route for this
thanks everyone
You don't use it instead of blade you mostly use it with or inside blade.
Use Vue like normally would just treat your blade template as your plain HTML.

Is it best practice to use Vue component in blade template?

I'm using multiple Vue components in Laravel blade template like below
<div id="app">
<user-list></user-list>
<first-component></first-component>
<seconde-component>
<h1>{{ $name }}</h1>
<p>{{ $bio }}</p>
</seconde-component>
</div>
I want to know if it's best practice to use Vue like this or not? If
not, what is best practice for using Vue components in Laravel?
Laravel has VueJS support right out of the box. You can you use any front-end library like AngularJS or ReactJS too inside if you Laravel app. According to the Laravel docs there is not a "best practice or method" to using VueJS in Laravel. It it just supported if you choose to use the library.
To help your Laravel application you can setup a VueJS router for live loading, use ajax to get json from your laravel app without refreshing, est.

VueJs view in laravel

I wonder how can i get my page parts such as sidebar or header with Vue way?
currently I get them like #include('admin.parts.header') which is blade template, but is it possible i move them to components (header.vue) and get them with vue way like <router-view name="header"></router-view> ?
The correct way to import via #include. You need to import vue components only with vue, blade with blade.
the solution was to have div with id around my sidebar.vue (eg) template and call that id instead of in my main component.

Using Laravel includes inside a vue component?

I have a set of components, some components include other components via #include('my-sub-component')
The issue is that when I want to use vue I have to put the entire component in the vue.js file inside the template tags.
But inside the template I want to use the #include so I can include some sub components. This does not work.
How can I include blade components inside a vue component?
As far as I know, it's impossible. You can't use PHP (Laravel Blade) .blade.php tags inside Vue Component .js, of course Vue can't execute PHP script in this case. The possible use case is you use the Vue Component inside Laravel Blade.
The closest thing you can get to this is to use inline templates. You can't access blade directives it if you are writing your templates in single file components and compiling them with webpack or something because they are not being rendered with PHP.
You could put the style and scripts components in the SFC though and but in order to use blade directives the template would need to be in a .blade.php file

Laravel blade soft-migrating to Vue.js - how to handle tags?

I have a Laravel application using blade templates. I want to start learning and migrating the tamplates to Vue, but one part at a time, so I would use both Blade and Vue.js on my code for some time, until I fully migrate to vue.
My problem is, they have similar tags {{ varname }} is exactly the same on both Blade and Vue.
I'm a beginner to Vue.js. My question is, how to approach this? How could I use both at the same time?
You can escape {{ }} in Blade by prefixing #.
https://laravel.com/docs/5.3/blade#blade-and-javascript-frameworks
#{{ varname }}

Resources