Vue Template не рендерится (нет ошибки в консоли) - PullRequest
1 голос
/ 08 октября 2019

В настоящее время я пытаюсь записать несколько файлов .vue, которые позже смогу использовать в качестве тегов-шаблонов с синтаксисом лезвия Laravel.

Я записал необходимые строки для использования vue в моем app.js, зарегистрированноммои компоненты, чтобы использовать синтаксис моих файлов.

Однако я запускаю npm run dev с успехом и без ошибок. Тем не менее мое Vue не отображается && Chrome Dev Console не отображает ошибок (Vue.js не обнаружен)

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>

1 Ответ

0 голосов
/ 08 октября 2019

Ваш app.js внутри головы исполняется до синтаксического анализа dom (пока нет #app).

Либо переместите его в нижнюю часть тела

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

, либоadd defer

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

Или добавить код vue в событие, загруженное в контент dom

window.addEventListener("load", function(event) {
    new Vue({...})
});
...