0
votes

I'm starting to use vue js in my Laravel project. I installed all packages, but my problem is when I try to call a component inside another component and I run this command :

npm run dev

I had an error from webpack.

My Code:

the parent component TabelReception.vue:

<template>
<stats-card></stats-card>
    <table class="table">
        <tbody>
        </tbody>
    </table>
</template>
<script>
    import StatsCard from './StatsCard'
    Vue.component('StatsCard', StatsCard)
    export default {
        components: {
            'stats-card': StatsCard 
        }
    }
</script>

The soon component StatsCard.vue:

<template>
<h2>
hi bro just a test 
</h2>
</template>
<script>
    export default {
    }
</script>

app.js:

import Vue from 'vue'
/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Vue.component('reception-table', require('./components/TableReception.vue').default);
Vue.component('stats-card', require('./components/StatsCard.vue').default);
/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

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

please help .

2
Hi, can you post the errors you're getting? Describing your configuration may also be helpful to assist you in working out the problem - Robert Foster

2 Answers

1
votes

The component allow only single element in the template section. If you need to use multiple, wrap it with div and make it single like

<template>
  <div>
    <stats-card></stats-card>  
    <table class="table"> 
        <tbody>

        </tbody>
    </table>
  </div>  
</template>

You don't need to use both methods to register a component

<script>
   import StatsCard from './StatsCard'

   export default {
        components: {
          StatsCard
        }
    }
</script>
0
votes

<template>
    <div>
        <stats-card>
        </stats-card>
    
        <table class="table">
    
    
            <tbody>
    
    
            </tbody>
        </table>
    </div>
</template>

<script>
import StatsCard from './statccard'


export default {
    components: {

        'stats-card': StatsCard
    }
}
</script>
the  template root on requires one ony one element but you have also iported the component wrongly