Include a Vue component within another Vue component in a Laravel application using VueJs

I've recently integrated Vue.js into my Laravel project and encountered an issue when trying to call a component within another component. After running the command npm run dev, I received a webpack error.

Here is the code snippet from my 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 child component, StatsCard.vue:


<template>
    <h2>
        hi bro just a test 
    </h2>
</template>

<script>
export default {
}
</script>

And here's a snippet from my app.js file:


import Vue from 'vue'

Vue.component('reception-table', require('./components/TableReception.vue').default);
Vue.component('stats-card', require('./components/StatsCard.vue').default);

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

If anyone could provide some guidance on this issue, it would be greatly appreciated.

Answer №1

Only one element is allowed in the template section by the component. If you need to include multiple elements, wrap them with a div tag and keep it as a single entity like this:

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

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

You do not have to use both methods to register a component

<script>
   import StatsCard from './StatsCard'

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

Answer №2

<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>

Make sure to only have one root element in the template section and double check component imports.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display a compilation either in the backend or the frontend

I'm fairly new to NodeJS and I could really use some advice. I currently have a webpage that displays a list of users, which is retrieved from a collection using Mongoose. I am aware of two different ways to display this list: 1) One option is to que ...

How can I insert an HTML/PHP code snippet into a <ul> list using JavaScript?

My upload.php file saves images into an uploads/ folder within my main directory. I am looking to dynamically add a new li tag to my index file each time an image successfully uploads. Here is a snippet from index.php: <ul> <li><im ...

Is it viable to create an onClick event for the text content within a text area?

I'm working on a project that involves displaying XML data in a textarea and creating an onClick event for the content within the textarea. For example: <textarea>Hello Web, This is a simple HTML page.</textarea> My goal here is to cre ...

Incorrect script enqueue order in child theme of WordPress

Help needed with enqueuing a script in a WordPress child theme. Despite specifying Jquery dependency, the script is loaded before Jquery. The code in question: add_action( 'wp_enqueue_scripts', 'child_theme_scripts' ); function child_ ...

"Encountering issues with autocomplete feature loading empty data when attempting to populate several fields simultaneously

Encountering issues with autocomplete when trying to select a value and fill in multiple fields. Seeing small blank lines on autocomplete and search stops while typing. Suspecting the problem lies within .data("ui-autocomplete")._renderItem or ...

SweetConfirm: The Perfect Combination of Vue and Laravel

I am attempting to delete my data after confirmation, and I would like to utilize sweetalert for this purpose. 1 If I use a simple alert like: deletePage(index) { if (confirm("Do you really want to delete it?")) { let page = this.pages[index]; axio ...

Progress bar carousel component based on advancement movements

Here is the mockup I am working with: https://i.sstatic.net/bIepQ.png So far, I have made good progress with this code: https://codesandbox.io/s/codepen-with-react-forked-16t6rv?file=/src/components/TrendingNFTs.js However, I am facing a couple of challe ...

leveraging a Nuxt plugin and saving it in middleware

My goal is to create a middleware that validates the authentication and entitlement of users. The authentication details are retrieved from my store: //store/index.js const state = () => ({ auth: { isLoggedIn: false // more properties here } ...

Node.js not resetting array properly

I have successfully set up a Node+Express API that is working smoothly, but I am facing an issue with returning responses for complex queries. The problem lies in the fact that the variable where I store the response data is not being reset between differe ...

Is there a way to obtain the full class name if only a portion of it is known?

I am trying to extract the complete classname of an element, but I only have partial information about it. <div class="anotherclass my-class-no-1 onemoreclass...">div> Currently, I can select the element using this: $([class*="my-class-no-"]... ...

Exploring each item within oData: A guide

After writing the code statement above, I am able to see the attached image. Now, my challenge is accessing the "label" property inside each object. How can I iterate through these objects and retrieve their "label" properties? item.getModel().oData; I a ...

Packages starting with @ are found in the Node.js ecosystem

What's the deal with libraries in Node.js starting with @ symbols? Is there a specific convention for this? I feel like I'm missing something obvious here. ...

The disabled functionality of AddCircleIcon in Material UI seems to be malfunctioning

The AddCircleIcon button's disabled functionality is not working, even though the onClick function is functioning properly. Even when directly passing true to the disabled property, it still doesn't work. I am in need of assistance to resolve thi ...

The HTML canvas may sometimes produce inaccuracies in the bytes returned by the getImageData function, a phenomenon known as "

I've come across an issue where the getImageData function of an HTML canvas is returning incorrect byte values. To illustrate, I created a 1x1 pixel image using the following Python code: from PIL import Image import numpy as np a = np.array([[[12, ...

The unexpected blank space appearing beneath my website as a result of images and videos placed on the

There seems to be some random white space on my website between the main body elements and the footer. Interestingly, removing the cat image and videoplayer eliminates this white space. However, I don't want to remove them completely, so I'm tryi ...

Exploring Firefox webpage data with JavaScript or browser extensions

Have you ever wondered if it's possible to retrieve the "Modified" information seen in Firefox when selecting "View page Info" by just using a JavaScript extension? ...

turn on labels for every individual cell in the bar graph

I'm working on setting labels of A, B, and C for each bar chart cell to display all my data on the chart. I attempted using data.addColumn('string', 'Alphabets'); but it's not functioning as expected. It seems like a simple ta ...

The bootstrap datepicker does not display the date range on the calendar

I tried to incorporate a bootstrap datepicker date-range in the code snippet below, but I am encountering an issue where the selected date range is not displaying on the calendar. <!DOCTYPE html> <html> <head> <link rel="stylesheet" ...

Using Node.js to save a typed array to a file系统, 读/写 typed

I am working with a typed array that contains the values Uint16Array(2) [ 60891, 11722 ]. My goal is to save this array to a binary file and then retrieve it while preserving the order of the elements. Despite my attempts using the fs module, I have encou ...

Include an Open OnClick event in the React/JSX script

We have a dynamic menu created using JavaScript (React/JSX) that opens on hover due to styling. My inquiries are: Instead of relying on CSS for the hover effect, where in the code can I implement an OnClick event to trigger the menu opening using Java ...