How to create a component and add it to Blade in Laravel?

Go to you app.js file “resources\js\app.js” and add this:

Vue.component('view-dashboard-component', () => import('./components/Admin/Navbar/DashboardComponent.vue'));

Make sure you create 2 vue folders called “Admin/Navbar/” inside the components vue folder in “resources\js\components”

In your vue file add this:

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Example Component</div>
                    <div class="card-body">
                        I'm an example component.
    export default {
        mounted() {
            console.log('Component mounted.')

Just above this:

const app = new Vue({
    el: '#app',

Now create a Laravel view blade file, and add this in it:



To get to this file, create a route in your “routes\web.php” and add this:

    Route::get('/admin/dashboard', 'Admin\[email protected]');

In your controller make sure you have this:

public function index() {
return view('admin.dashboard.index');

Now type your domain as:

and you should see your component