saqueib
429
3
Vue

How to extend the app instance on specific laravel blade view

Posted 2 years ago by saqueib

I am very new in vue.js please help me on this, by default Laravel 5.3 comes with vue integrated, in assets/js/app.js file it initializes the vue instance.

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

I can make some global vue component and require them before initialization code in app.js.

But I want to have some data, method and components unique on specific page (.blade.php). for example, I need one form on login view and another list of posts in a different view.

How can I extend the vue app instance on the specific page and add local components etc.

I have @stack('scripts') in my layout. I wanted to do something like this

@push('scripts')
<script>
    app.src = "{{ $me->avatar }}";

    app.methods = {
        imageuploaded (src) {
            this.src = src;
        }
    }
</script>
@endpush

Please help how I can do it, or any other best way to deal with this problem.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.