Passing data to child Vue component and iterating through it

Working with the axios call to fetch data from an API has been my current challenge. I am aiming to integrate the Home and ListItem components seamlessly.

<template>
    <div>
            <list-item v-for="idea in ideaList" :key="idea.id"></list-item>
    </div>
</template>
<script>
    import ListItem from '../components/ListItem'
    let AddIdea = require('../components/AddIdea.vue');
    export default {
        name: "HomePage",
        components: {AddIdea, ListItem},
        data() {
            return {
                addActive: "",
                ideaList: {},
                errors: {},
            }
        },
        mounted() {
            axios.post('/getData')
                .then((response) => this.ideaList = response.data)
                .catch((error) => this.errors = error.response.data);
        },
    }
</script>

My main concern lies in passing the IdeaList values to the ListItem component and rendering them using a loop. Despite my efforts to insert props as follows:

<script>
export default {
    name: "ListItem",
    data() {
        return {
            props: ['idea']
        }
    }
}

and displaying the value:

<template>
<span class="column is-8">
    {{idea.title}}
</span></template>

Where should I seek guidance on getting this feature to function correctly?

Answer №1

It is important to clarify whether you intend to pass the complete list or just an iterated object to ListItem. There are two clear mistakes that need to be addressed.

Firstly, you have forgotten to declare the prop intended to be passed to ListItem.

<list-item v-for="idea in ideaList" :key="idea.id" :idea="idea"></list-item>

Additionally, remember that props should not be declared within the data object of the ListItem component.

export default {
    name: "ListItem",
    props: ["idea"]
}

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

Unable to locate the Chart object within the chartjs-plugin-labels.js file

Hello there, I am currently working on an Angular project where I want to incorporate a chart plugin. To achieve this, I executed the following commands: npm install angular2-chartjs npm install chartjs-plugin-labels Following that, I imported it into my ...

Exploring methods to retrieve data from the web3 platform through Node.js

Is there a way to retrieve token information such as name, symbol, and decimals using Nodejs in conjunction with web3js? ...

Leveraging Google's API URL within a VueJS framework

Here is a URL example: https://example-url.com When attempting to use this URL in axios, an error occurs. The request to 'https://example-url.com' has been blocked by the CORS policy due to missing 'Access-Control-Allow-Origin' heade ...

Passing a value back to a template from a promise

Currently, I am implementing server-side validation for dynamically created input fields within div tags. The issue I am facing is that I need to display the API error message in my template instead of directly setting it in my controller. If I set it in t ...

Having trouble changing my array state in react?

I'm having trouble understanding why my React state isn't updating with the following code: state = { popUpMessages:[] } popUpMessage(id,name) { console.log("id ",id,"name ",name) const addUserObject = { id, name }; const new ...

Node.js web tracing for tracking requests

Currently, I am developing a web application using node and express. I am facing a challenge in tracking the execution of web requests from start to finish, especially when it involves database calls. I have experimented with async_hook APIs, but encount ...

Utilizing AJAX to seamlessly transfer id elements to a database

I have the following working code: <script> function displayUserData(str) { if (str=="") { document.getElementById("userDetails").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLH ...

Is there a way to halt the Vue Nuxt development server from running in the VS Code Console?

When using Vue Nuxt, I usually launch the development server with the command "npm run dev". However, I am looking for a way to stop the server from the VS Code console. Currently, the only method I know is to close the Terminal Window. Is there a better ...

"Trouble arises with the match() function in relation to email regex validation

After retrieving the HTML content from a website with my function, I am using String.prototype.match along with a regex rule to extract email addresses from that page. However, the issue is that I am receiving a line that matches the regex but does not con ...

Dividing a string into sections and sending each section to a function

I'm currently facing an issue while trying to pass string objects to a function. The query string in the URL contains fields that are in a comma-separated string format with attributes of interest. I've stored the attribute names in the fields a ...

utilize regular JavaScript to manage Vue.js events beyond the component's scope

There is a VueJs component embedded in a regular web page. Whenever the component triggers an event, I need the regular web page to react accordingly. Is this achievable? The Sites.vue component is a single file element placed within the content of the re ...

I can't understand why this question continues to linger, I just want to remove it

Is there a valid reason for this question to persist? I'm considering removing it. ...

The option to clear searches is missing from the iOS interface

My application is designed to perform searches using post codes, and for the most part, it functions properly. However, I have encountered an issue where the clear icon on the right-hand side of the field does not display in certain browsers. To investiga ...

Within Blade, Laravel and Vue components are able to communicate by sharing data from one component to another

Is it possible to achieve this task? Here is the scenario: I have a left navbar displaying membership status (active/inactive). Once the payment gateway receives the payment, a webhook is triggered via Paddle(Laravel Paddle API). During the webhook proc ...

My API encountered a 404 error when trying to access the MAILCHIMP API

I am currently working on a project focused on creating a Newsletter for web development led by Angela Yu. In this project, I encountered a 404 error while integrating the API from the MAILCHIMP website. Each time I tried to insert the API, it consistent ...

Tips on showcasing a set number of elements from an array in React

How can I modify my code to display only a specific number of items from the 'portfolioComponents' array, starting at a designated index ('startArrayHere') and incrementing or decrementing that index based on user interaction? I've ...

Collaborate and pass around SQL connections among different modules

One of my recently developed modules consists of three main functions: Establishing a SQL connection Executing a query Closing the connection This module is called in script.js along with other custom modules responsible for various operations that requi ...

Pass along computed style data to the parent component in Vue.js

I am relatively new to VueJS and currently in the process of exploring its features. One specific issue I am facing on my website involves a TopBar component that includes both the logo and the menu. <template> <div id="topBar"> <div ...

Attempting to reduce the width of the dig when it reaches 400

I have a square element with a click event that increases its size by 50 pixels on each click. However, once it reaches a size of 400 pixels, the size decreases by 50 pixels with every click instead. Additionally, when the size of the square reaches 100 p ...

Form fields will not automatically populate with link parameters; the user must manually input the information

My form fetches data from the database using server-side code when the user inputs the "user_id" field. The User ID field is the primary field on the form, and when the user enters their user ID, all other fields retrieve the corresponding user data from t ...