Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vue.js component in laravel blade?

I registered component in my app.js like this:

Vue.component('navbar', require('./components/Navbar.vue'));

Now I want to import that component:

<template>
<nav class="navbar">CODE HERE</nav>
</template>

Into my blade.php file:

<body class="">
    <div id="app">
        <div class="">
        <navbar></navbar> <-- here!
        @yield('content')
        </div>
    </div>
</body>

What's the easiest way to do this?

like image 806
Rowinski Bartosz Avatar asked Sep 06 '17 08:09

Rowinski Bartosz


2 Answers

In app.js

import navbar from './components/Navbar.vue';
Vue.component('navbar', require('./components/Navbar.vue'));

var app = new Vue({
   el: '#app',
   components: {
       'navbar': require('./components/Navbar.vue'),
   }
});

In your blade:

<body class="">
<div id="app">
    <div class="">
       <navbar></navbar>
       @yield('content')
    </div>
</div>

like image 128
Hiren Gohel Avatar answered Sep 18 '22 18:09

Hiren Gohel


It's an old thread, but: don't forget to run npm run dev to compile the app.js

like image 38
PJ.Wanderson Avatar answered Sep 17 '22 18:09

PJ.Wanderson