0
votes

I am trying to make a laravel application with vue js. I am new to vue, so learning a lot yet. Now my application has two interfaces. One for admin panel and the other for normal users. Now when I am including the vue components in admin panel's blade under a div with id "app" as defined in app.js, the components are working fine. But when I am trying to include some components in the normal use's interface under a div with id "app2" with defining 'app2' in app.js just like 'app'. But it is not working. How can I make the components work in the user interface's blade?

Here is my profile blade. where I am trying to show the component

@extends('layouts.main')
@section('body_content')

<div id='app2'>
    <profile-component></profile-component>
</div>

@endsection

Here is my modification in app.js

Vue.component('profile-component', require('./components/Profile.vue'));
const app2 = new Vue({
  el: '#app2',
});

and finally here is the profile component

<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card card-default">

                    <h1>Profile Page</h1>

                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>
1
at what level you debug? put console.log in app.js and check that whether it is loading or not ? - Niklesh Raut
what if you change app2 to app - Niklesh Raut
It is becuase you are creating another Vue instance when you do const app2 = new Vue({el: 'app2'}) - Presmelito

1 Answers

0
votes
Vue.component('my-component-a', {
  template: '<div>A custom component A!</div>'
});

Vue.component('my-component-b', {
  template: '<div>A custom component B!</div>'
});

const app1 = new Vue({
    el: '#app1',
    template: '<div><my-component-a /><my-component-b /><my-component-c /></div>',
    components: {
      MyComponentC: {
        template: '<div>A custom component C!</div>'
      }
    }
});

const app2 = new Vue({
    el: '#app2',
    template: '<div><my-component-b /><my-component-a /><my-component-c /></div>'
});
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<div id="app1"></div>
<div id="app2"></div>

Try This