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:

<template>
    <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.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Just above this:

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

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

resources\views\admin\dashboard\index.blade.php
@extends('layouts.app')

@section('content')
    <view-dashboard-component></view-dashboard-component>
@endsection

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

    Route::get('/admin/dashboard', 'Admin\DashboardController@index');

In your controller make sure you have this:

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

Now type your domain as:

www.mydomain.com/admin/dashboard

and you should see your component

Enjoy!