[Vuejs]-Can we use laravel blade templates in vue routing instead of vue components?

0👍

To my knowledge, you can’t. Since Laravel is not actually serving *.blade.php files to you but rather compiles them to plain PHP, puts into storage/framework/views (by default) folder and then serves.

From official docs:

In fact, all Blade views are compiled into plain PHP code and cached until they are modified

So in any case, there would have to happen a page refresh to serve other PHP file.

0👍

You can use ajax to get html as response and render in vue.

In your controller:

public function renderHtml()
{
   $data = ... ;
   $html = view('test',compact('data')->render();
   return response()->json($html);
}

In your Vue component use vanilla JS or jquery to get the markup and bind it to the comonent

fetch('renderhtml')
   .then(response => () {
       element.innerHTML(response.data);
});

Note that this is not a really reliable solution for every case.

Leave a comment