Home > Back-end >  Laravel Vue Component not Loading in Browser
Laravel Vue Component not Loading in Browser

Time:11-14

require("./bootstrap");

window.Vue = require("vue").default;

Vue.component(
    "example-component",
    require("./components/ExampleComponent.vue").default
);

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

<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>

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
    </head>


    <body class="antialiased">
    <div id="app">
        <example-component />
    </div>

        <script src="{{ asset('js/app.js') }}"></script>
    </body>
</html>

CodePudding user response:

do you run npm install && npm run dev ?

CodePudding user response:

This is how I solved this problem

  1. $ laravel new app-name

  2. $ cd app-name

  3. $ composer require laravel/ui

  4. $ php artisan ui vue

  5. $ npm install && npm run dev

  6. <script src="{{ asset('/js/app.js') }}"></script>

  7. <div id="app"> <component-name></component-name></div>

  8. npm run watch

  • Related