Define vuejs component in blade

@extends('layouts.app')
@section('body')
    <div class="general_wrapper" id="profile">
        @component('components.nav.main')
            @slot('menu')
                <div class="nav_menu">
                    <ul>
                        <li :class="{'active': tab==0}" @click="tabSelect(0)">
                           item0
                        </li>
                        <li :class="{'active': tab==1}" @click="tabSelect(1)">
                           item1
                        </li>
                    </ul>
                </div>
            @endslot
        @endcomponent
    </div>
@endsection
@section('script')
    <script>
        const profile = new Vue({
            el: '#app',
            data: {
                tab: 0
            },
            methods: {
                tabSelect(id) {
                    profile.tab = id;
                }
            }
        });
    </script>
@endsection

I need this bunch of code inside my project. I don't know what wrong with it. I got this error:

Property or method "tab" is not defined on the instance but referenced during render.

I removed 'const app = new Vue({ el: '#app'});' from app.js it works, but I have another Vue component in my project, and this made another one unknown...

Answers:

Answer

You need to define a container for you app

For eg.

<div id="app"> 
  Inside your vue component
</div>

so you can defina a vue component that use the container used in el setting

el: '#app',

maybe you will have some problem between blade and vue tags {{}}. Maybe you will can use @{{}} to specify vue vars

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.