Sending information from a parent component to a child component in Vue.js and then showcasing the data

Hey there! I'm new to vue.js and I'm struggling to figure out why my data is not being passed to the child component. I've tried a few different approaches, but none seem to be working as expected. It feels like I'm really close, but something just isn't clicking. Can you take a look at my setup in App.vue:

<template>
    <div class="app">
        <Header/>
        <div class="row">
            <div class="col-3">
                <Services v-bind:services="services"></Services>
            </div>
        </div>
    </div>
</template>

<script>
    import Header from "./components/Header.vue";
    import Services from "@/components/Service";

    export default {
        nam: 'App',
        components: {
            Services,
            Header,
        },
        data: function () {
            return {
                services: [{
                    title: "Logo flatdesign",
                    description: "I create amazing flat designs.",
                    image: "https://example.com/image1.jpg",
                    price: 6.7,
                    rate: 4,
                    id:1
                },{
                    title: "Quick Logo",
                    description: "I can quickly design a logo.",
                    image: "https://example.com/image2.jpg",
                    price: 5.5,
                    rate: 3,
                    id:2
                },{
                    title: "Another Flat Design Logo",
                    description: "I specialize in super flat designs.",
                    image: "https://example.com/image3.jpg",
                    price: 6.7,
                    rate: 4,
                    id:3
                }]
            }
        }
    }

</script>

<style>
</style>

Service.vue

<template>
    <div class="home">
        <div class="row">
            <div class="col-3" v-for="service in services" v-bind:key="service.id">
                <div class="jumbotron">
                    <img :src="service.image" height="100%" width="100%">
                    <h4>
                        {{service.title}}
                    </h4>
                    <div class="row">
                        <div class="col rate">
                            {{service.rate}} ★
                        </div>
                        <div class="col price">
                            {{service.price}} €
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
</script>

<style scoped>
    .rate{
        color: yellow;
    }
    .price{
        font-weight: bold;
    }
</style>

I appreciate any help or guidance you can provide. Thank you so much for your assistance!

Answer №1

To ensure proper functionality in your child component, make sure to include the following code snippet within the script section:

export default {
  name: "ChildComponent",
  props: ['data']
};

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

Issue with setTimeout function when used in conjunction with an ajax call

Currently, I am developing a quiz portal where questions are organized in modules. Each module consists of 5 questions: the first 4 are text-based, and the 5th is an image-based question. Upon registering through register.php, users are directed to index. ...

Can you explain the significance of the 'X-Bandwidth-Est 3' error message that states, "Refused to get unsafe header"?

I'm currently facing an issue with all the websites I am working on where I keep encountering the following error: Refused to get unsafe header "X-Bandwidth-Est 3" in base.js. This error seems to be related to a YouTube file named base.js, but after ...

Challenge with Vite, React, and MSW Integration

Having some trouble setting up MSW in a React application. It's unusual for me to come across issues like this. I've configured an environment variable VITE_MOCK set to true when running the yarn start:mock command. This should enable API mocking ...

Using Stringify to modify the value of a particular array in Local Storage

Uncertain of the accuracy of my question, but I am attempting to modify a value within a localstorage array. This is what my localstorage currently contains: [{"id":"item-1","href":"google.com","icon":"google.com"}, {"id":"item-2","href":"youtube.com","i ...

Interacting with a card in vuejs won't trigger any action

Is there a way to make an overlay disappear when clicking anywhere on the screen except for a specific card positioned on top of it? The current setup makes the overlay disappear even when the card is clicked. How can this behavior be corrected? <div ...

Is there a way for me to update the button text and class to make it toggle-like

Is there a way to switch the button text and class when toggling? Currently, the default settings show a blue button with "Show" text, but upon click it should change to "Hide" with a white button background. <button class="btn exam-int-btn">Show< ...

An issue arises with the Datatables destroy function

Utilizing datatables.js to generate a report table on my page with filters. However, when applying any of the filters, the data returned has varying column counts which prompts me to destroy and recreate the table. Unfortunately, an error message pops up ...

Obtain the v-if condition or data as plain text within a child component

Hey there! I'm currently working on creating a custom Vue component that is displayed based on the v-if directive. I also need to be able to update the value of the directive data (modalStatus) from within the component. <modal v-if="modalStatus" ...

Retrieve the image information from a specified element in the Document Object Model

Is it possible to extract the image data of a DOM element using standard JavaScript or browser extensions? I'm considering scenarios where: Creating an offscreen DOM element Populating it with dynamically styled CSS content Retrieving its image dat ...

What is the best way to break out of a function halfway through?

What are your thoughts on using nested if statements? $scope.addToCart = function () { if (flagA) { if (flagB) { if (flagC) { alert('nononono!'); return; } } } e ...

Remove any words that are not included in the specified list

Here is the code snippet to achieve the desired functionality: const { words } = require("../../json/words.json") const args = message.content.split(' ') const wordss = words.filter(m=> m.includes(args)) if(args > 1 || !wordss) { ...

What could be causing this code to fail in making changes to the HTML document?

I tried incorporating the following code into my website: $('.feed-item').append('<p> This is paragraph element. </p>'); You can view it on this page: Test Unfortunately, the code does not seem to be functioning properly. ...

What could be the reason behind getting a useLayoutEffect error when using renderToString to render a Material-UI component?

Currently, I am utilizing React version 16.12.0 along with @MaterialUI/core version 4.8.1. The challenge I am facing involves creating a custom icon for a React Leaflet Marker. The icon in question is a Fab component sourced from Material-UI. In order to ...

Why is my MySQL query not returning the most recent results when using setInterval()?

I am currently facing an issue with the setInterval function within the $(document).ready(function(){} My approach involves using setInterval to call a PHP script that executes MySQL queries to check the status of 4 switches and then updating the screen w ...

Highlighted option selection in Material UI dropdown using Cypress

Can someone explain how to select Material-UI dropdown options using Cypress? I'm looking for a simple explanation, thanks! ...

Enhance Your jQuery Experience with Advanced Option Customization

I am currently developing a plugin that deals with settings variables that can be quite deep, sometimes reaching 3-4 levels. Following the common jQuery Plugin pattern, I have implemented a simple method for users to update settings on the go using the not ...

Vue paginated select with dynamic data loading

My API has a endpoint that provides a list of countries. The endpoint accepts the following query parameters: searchQuery // optional search string startFrom // index to start from count // number of options to return For example, a request with searchQu ...

TypeScript interface with an optional parameter that is treated as a required parameter

Within my interface, I have a property that can be optional. In the constructor, I set default values for this property, which are then overridden by values passed in as the first parameter. If no properties are set, the defaults are used. I am looking fo ...

Deploy quickly using Vite on Azure Devops

We are facing a challenge while deploying our new Vite +Vue3 application to the server. The issue lies with our outdated yaml file, which still includes a "--dest" option from our previous Vue 2 CLI deployment. Is there anyone familiar with how to specify ...

Parsing JSON sub items in Android application using Java

Here is a snippet of my PHP file: <?php $myObj = array( "name"=>"John" , "age"=>"30" , "post"=>[ "title"=>"What is WordPress" , "excerpt"=>"WordPress is a popular blogging platform" , ...