1

in our project, for templates for Vue.js, we write components in separate Blade files using x-templates like this:

<script type="x/templates" id="nameOfComponent">

The problem I have is that x-template content loading lately after other blade file content.

this is master.blade.php

<!DOCTYPE html>
<html lang="">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>@yield('title', 'base')</title>

    </head>
    <body>
        <div id="app">
            @yield('content')
        </div>
              
        <script src="{{ asset('js/app.js') }}"></script>

        @stack('scripts')
        @yield('script')

    </body>
</html>

and this is index.blade.php

test home page

<my-checkbox></my-checkbox>

@push('scripts')
    <script type="text/x-template" id="checkbox-template">
        <div class="checkbox-wrapper" @click="check">
        <div :class="{ checkbox: true, checked: checked }"></div>
        <h1>checkbox</h1>
        <div class="title">@{{ title }}</div>
        </div>
    </script>

    <script>
        Vue.component('my-checkbox', {
            template: '#checkbox-template',
            data() {
                return { checked: false, title: 'Check me' }
            },
            methods: {
                check() { this.checked = !this.checked; }
            }
        });
    </script>
@endpush

and this is app.js

window.Vue = require('vue');



window.addEventListener("load", function (event) {
    Vue.component('example-component', require('./components/ExampleComponent.vue').default);
    
    const app = new Vue({
        el: '#app',
    });
});

how can I make all content loading in the same time? thanks.

1
  • I think this question is way underrated, thanks you so much! Commented Jul 2, 2021 at 11:59

1 Answer 1

2

Blade file is for server rendering and vue template is for client one, that's why it's "slower". In your case you may want to hide the page till vue finishes loading. Checkout the v-cloak directive. For more detail: https://v2.vuejs.org/v2/api/#v-cloak

Sign up to request clarification or add additional context in comments.

4 Comments

thank you, I will check the link and try your solution.
I tried this solution and my problem is fixed, but it make all page loaded slowly. why Vue instance take this time to be ready? can we make it faster?
It's not just the vue instance but all the libs coming with vue as well. I know some tools such as wepack or gulp to minimize js files and help the web build/run faster. But it takes time to get used to them.
we already use wepack in our project and we can minimize js files before run production. thank you for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.