2

I am currently trying to write multiple .vue files, which I can later on use as template tags with Laravel's Blade Syntax.

I wrote down the neccessary lines to use vue in my app.js, registered my components in order to use the syntax of my files.

However, I run npm run dev with success and without erros. Nevertheless my Vue is not rendered && Chrome Dev Console displays no erros (Vue.js not detected)

app.js

require('./bootstrap');

// import Vue from 'vue'
// import VueRouter from 'vue-router'
// import TriviaGame from './components/TriviaGame.vue'
// import Dashboard from './components/Dashboard.vue';

Window.vue = require('vue');


// Vue.use(VueRouter)

// Vue.config.productionTip = false
Vue.component('trivia-game', require('./components/TriviaGame.vue')).default;
Vue.component('dashboard', require('./components/Dashboard.vue')).default;

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


// const routes = [
//     { path: '/', component: Dashboard },
//     { path: '/trivia', component: TriviaGame }
// ]

// const router = new VueRouter({
//     mode: 'history',
//     routes
// })

// new Vue({
//     router,
//     render: h => h(Dashboard)
// }).$mount('#app')

welcome.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">
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
        <script src="{{asset('js/app.js')}}"></script>
        <title>Vue SPA</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">

        <!-- Styles -->
        <style>
            html, body {
                background-color: #fff;
                color: #636b6f;
                font-family: 'Nunito', sans-serif;
                font-weight: 200;
                height: 100vh;
                margin: 0;
            }

            .full-height {
                height: 100vh;
            }

            .flex-center {
                align-items: center;
                display: flex;
                justify-content: center;
            }

            .position-ref {
                position: relative;
            }

            .top-right {
                position: absolute;
                right: 10px;
                top: 18px;
            }

            .content {
                text-align: center;
            }

            .title {
                font-size: 84px;
            }

            .links > a {
                color: #636b6f;
                padding: 0 25px;
                font-size: 13px;
                font-weight: 600;
                letter-spacing: .1rem;
                text-decoration: none;
                text-transform: uppercase;
            }

            .m-b-md {
                margin-bottom: 30px;
            }
        </style>
    </head>
    <body>
       <p>This is just an example</p>
       <div id="app">
       <trivia-game></trivia-game>


        </div>

    </body>
</html>
  • Watch [this](https://stackoverflow.com/questions/41215867/why-is-vue-js-chrome-devtools-not-detecting-vue-js), may will help – boolfalse Oct 08 '19 at 13:22
  • Well actually this more an issue related to my code and not by the devtool itself. – questionsaboutmycode Oct 08 '19 at 13:25
  • you are setting `Window.vue`(lowercase vue) but using Vue (first letter upper-case) in `Vue.component` and `new Vue`. But that should at least trigger an error... – Constantin Groß Oct 08 '19 at 13:25
  • Try and check if your main instance is being initialised, add a `mounted` hook to it and try to log something – Ayrton Oct 08 '19 at 13:29

1 Answers1

0

Your app.js inside the head is being executed before the dom is parsing (no #app yet).

Either move it to the bottom of the body

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

or add defer

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

Or add the vue code inside a dom content loaded event

window.addEventListener("load", function(event) {
    new Vue({...})
});
Robbin Benard
  • 1,542
  • 11
  • 15