3

So the standard example-component that is included with Laravel works just fine.

app.js:

require('./bootstrap');

window.Vue = require('vue');

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

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

ExampleComponent.vue:

<template>
    <div>
        <h2>TEXT</h2>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Blade:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Dashboard</div>
                <div class="card-body" id="app">
                    <example-component></example-component>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

app.blade.php

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

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title></title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div>
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                </a>

                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">

                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        <a class="navbar-brand" href="{{ url('/') }}">
                            Mayer
                        </a>
                    </ul>
                </div>
            </div>
        </nav>

        <main class="py-4">
            @yield('content')
        </main>
    </div>
</body>
</html>

And im still only seeing the stuff from the example-component that ships with laravel.

(https://prnt.sc/r5cbtr)

But when I make a change to the ExampleComponent like adding a h2-tag or something the blade doesn't update and the change wont come through.

I also ran npm run watch, still no change.

Hope someone can help.

Edit:

7
  • Where you load the app.js file? And where you create the new Vue instance? Commented Feb 20, 2020 at 19:30
  • @porloscerrosΨ in layouts/app.blade.php <script src="{{ asset('js/app.js') }}" defer></script>, when i remove this even the example-component doesn't work anymore.
    – Zamoht
    Commented Feb 20, 2020 at 19:39
  • So you can see the component on your browser but can not see the changes and you have running npm run watch? Make sure you doesn't have another <div id="app"> in the layout blade too. I can't see anything wrong in your code, but would be usefull if you share the entirely app.js and the layout.blade because maybe the issue is in another place Commented Feb 20, 2020 at 19:53
  • @porloscerrosΨ I added the app.blade.php, the whole app.js and you can see that I made some changes to the ExampleComponent.vue but I still only get stuff that you can see in the screenshot down below.
    – Zamoht
    Commented Feb 20, 2020 at 20:04
  • 1
    @porloscerrosΨ I found the error myself now, I had to disable cache in google chrome, now its working
    – Zamoht
    Commented Feb 20, 2020 at 20:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.