Error message: Component nesting/recursion error, component not registered

I am facing an issue while using the component within itself in Nuxt.js. I'm getting the following error:

[Vue warn]: Unknown custom element: - Did you register the component correctly? For recursive components, make sure to provide the "name" option.

Here is how my code looks in components/MyComponent.vue

<template>
<div>
    <h1>{{ a.content }}</h1>
    <MyComponent :child="a.child" />
</div>
</template>

<script>

export default {
    data() {
        return {
            a : {},
        }
    },
    mounted() {
        axios.get('/api/blah/')
        .then((res) =>
        {
            this.a = res.data;
        })
        .catch((err) =>
        {
            console.error(err);
        });
    }
}
</script>

A similar piece of code worked fine with raw single-page HTML page using Vue.js, but I'm unsure about naming the component before using it here. How can I resolve this issue and make it work?

Answer №1

To ensure reusability of your component and avoid an infinite loop, it is essential to assign a name to it and carefully manage the rendering process:

<template>
<div>
    <h1>{{ b.title }}</h1>
    <ChildComponent :data="b.data" />
</div>
</template>

<script>

export default {
    name:"ChildComponent",
    props:['data'],
    data() {
        return {
            b : {},
        }
    },
    mounted() {
        axios.get('/api/endpoint/')
        .then((response) =>
        {
            this.b = response.data;
        })
        .catch((error) =>
        {
            console.error(error);
        });
    }
}
</script>

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

Error with the mongo (1.4.4) query

After running the query like this : collection.find({ "position": { $in: [ 1, 2 ] } }).toArray().... The correct result is returned. However, when I try using $and or $or, such as: collection.find({ $or: [ { "position": 1 }, { "position": 2 } ] }).toAr ...

Guide to generating customized CSS styles on-the-fly in Vue (similar to Angular's dynamic styling capabilities)

When working with Angular, we have the capability to dynamically set CSS properties. For example: <style ng-if="color"> .theme-color { color: {{color}}; } .theme-background-color { background-color: {{color}}; } .theme-border-color { border-color: { ...

Getting started with Vue.js Components

Being a newbie in the world of Vue.js, my question may seem quite basic. Bear with me, please. I've set up the components App.vue and Character.vue. My goal is to dynamically create characters and add them to an array in App.vue, then use Character.v ...

Ensure that the sidebar automatically scrolls to the bottom once the main content has reached the bottom

I am facing an issue with a sticky sidebar that has a fixed height of calc(100vh-90px) and the main content. The sidebar contains dynamic content, which may exceed its defined height, resulting in a scrollbar. On the other hand, the main content is lengthy ...

Tips for executing a function in Vuejs after the component is created:

I developed a component with a function that calls external APIs and fills an array. I utilized the created() lifecycle hook to execute the function initially. Now, I need this function to run again when a variable passed from the parent component changes. ...

Using Vuejs to display errors with alerts

Is there a way to display errors using alerts in bootstrap when working with vuejs? This is an example of the code: <div v-if="this.getError"> <div v-for="(_errors, key) in this.getError"> <p>{{key.repla ...

Can you tell me the performance metrics displayed in the Vue devtools alongside the components?

Looking for insights or resources on a feature in the Vue Dev Tools. In the components pane, there are little red and yellow squares that seem to indicate performance of components. These squares only appear after I update certain components, such as a tex ...

Tips for passing an extra parameter in Telerik MVC [JQuery] event handlers

Currently, I am new to jQuery and utilizing Telerik asp.net MVC control in conjunction with the Razor view engine. Below is a snippet of code from my view: Html.Telerik().ComboBox().Name("cmb") .AutoFill(true) .DataBinding(bind ...

Struggling to get this to function

Is there a way to modify the value of a variable? I have attempted to utilize "Promises," but it is not working and gives me an error. My goal is to load data into a table. /* Function for formatting row details */ function fnFormatDetails(oTable, nTr) { ...

Preventing the submission of a form using jQuery until all input, radio, select, and checkbox fields are filled out

I currently have a form that includes various field types, all of which must be filled out before submission. The submit button is disabled by default and I am looking to enable it once all fields are completed. I came across examples of this feature work ...

Utilizing mixins for vee-validation with Vue-test-utils in a Nuxt project

Currently, I am experimenting with testing the validation process for a form using vee-validate and vue-test-utils. My setup includes nuxt and a custom plugin that integrates vee-validate and provides two custom computed properties as a mixin. However, I ...

Is it possible for Javascript to handle a string of 27601 characters in length?

I have created a webmethod that returns an object containing strings. Each string in the object is of length 27601. This pattern continues for all array members - str(0) to str(n). When my webmethod returns this exact object, I encounter an issue on the c ...

Pop-up Registration Form Activation Using JQuery

I am attempting to create a Javascript jQuery registration form that appears in a pop-up window when a link is clicked. Here is the button I am working with: <a href="#" class="cta">REGISTER NOW</a> The goal is to have a simple HTML registra ...

Can anyone advise on the appropriate syntax to include in my if statement to verify the existence of a record within my MySQL query result?

How can I check for an existing record in my MySQL query using an if condition? I am looking to log 'Taken' if there is already a user with the posted username in my user table. db.query('SELECT username FROM user WHERE username = ?', ...

Is there a way to individually remove a selected radio button and its corresponding label?

Having trouble removing a selected radio button and its associated label. Struggling to implement the remove function that targets the selected radio button and removes both the button and label. function removeRadioItem() { var radios = document.getElem ...

Can you iterate through each element that matches those in a different array?

As a beginner in Javascript, I may stumble upon some obvious errors, so please bear with me. My goal is to iterate through two arrays and perform a loop for each element that exists in both arrays. Currently, this is my code: if(obtainedCards.some( sp =& ...

When material skinning is enabled, the skinned animation mesh in Three.js mysteriously vanishes

After exporting an animated model from Blender, I encountered an issue with instantiating it in my project. Although I was able to create the THREE.Animation and model, I found that the animation was not working. I soon discovered that I needed to set skin ...

Can we send a dynamic form using AJAX?

I am seeking a method to submit a page filled with quantities to another page and then retrieve their values. Here is my setup: <input type="number" name="item1" /> <input type="number" name="item2" /> <input type="number" name="item3" /> ...

Using JavaScript to adjust the width of the table header

I have a table that I need to adjust the width of using JavaScript or jQuery. <div class="dataTables_scrollHeadInner" > <table class="table table-condensed table-bordered table-striped dataTable no-footer" > <thead ...

Setting up Vue in Django application: Configuring Vue instance using static JavaScript files

I'm having trouble setting up the vue instance from a separate JavaScript file (rather than including the code in each HTML template). Here is an example of the template: <html> <head> <title>Cinema project</title> < ...