1
@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...

kazemm
  • 473
  • 5
  • 19

1 Answers1

2

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

  • My buddy, I defined it in app.js. 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... – kazemm Dec 18 '18 at 19:24
  • You should declare the components to use en you main.js or app.js vue component... for eg. `Vue.component('question', require('./components/questions/Question.vue'));` – Manuel Eduardo Romero Dec 19 '18 at 22:36
  • tnx buddy, I have problem in defining components, but now there is another issue: https://stackoverflow.com/questions/53887003/define-vue-application-in-blade-component – kazemm Dec 21 '18 at 15:14