7

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?

1

2 Answers 2

23

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>

Sign up to request clarification or add additional context in comments.

10 Comments

Unknown custom element: <navbar> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
Use import navbar from './components/Navbar.vue'; before Vue.component statement
Have you used export default { } for app.js??
What do u mean?
now error here 'navbar': require('./components/Navbar.vue');
|
9

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.