Muamar Collins
Muamar Collins

Reputation: 89

how to return a vuejs view in laravel routing file

I have a Laravel + VueJS application and I am having trouble with the following issue:

Here's my code:

routes/web.php-

Route::get('/pizzas', function () {
    return view('Pizzas');
});

the Vue file directory is resources/js/Pages/Pizzas.vue

Upvotes: 0

Views: 2522

Answers (1)

Wyrone
Wyrone

Reputation: 92

You can try to add your component to app.js(Im assuming you already have this in your resources folder) with:

window.Vue = require('vue');
Vue.component('pizza-component', require('./Pages/Pizzas.vue').default);
const app = new Vue({
    el: '#app',
});

And in your laravel blade, use the component like this:

<div id="app">
    <pizza-component></pizza-component>
</div>

This works for me when trying to use a Vue compnent in a blade template file

Upvotes: 1

Related Questions