Vue.js does not seem to be properly assigning attributes that are declared within the data object array

Trying to get a hang of vue.js and looking to create dynamic product cards using it:

This is the snippet from my HTML file:

<div id="app">
<card v-for="products in product" :productname="product.productname"></card>
</div>

Here's the vue.js template/component code I've written:

Vue.component('card', {
    props: [`productname`, `oldPrice`, `productPrice`, `productdetails`, `imgsrc`],

    template: `
    <div class="card">
    <div class="card-img-top">
       <img :src="imgsrc">
    </div>
    <div class="card-body">
        <h2>{{productname}}</h2>
        <p>{{productdetails}}.</p>
        <h6 class="product-price"><span class="old-price">{{oldPrice}} </span>{{productPrice}}</h6>
        <div class="rating">
            <span class="fa fa-star"></span>
            <span class="fa fa-star"></span>
            <span class="fa fa-star"></span>
            <span class="fa fa-star"></span>
            <span class="fa fa-star-half"></span>
            <span class="fa fa-star-o"></span>
        </div>
    </div>  
    </div>`
})

And here's the vue instance part:

new Vue({
el: "#app",

data: {
    product: [{
            imgsrc: 'img/41IP6IopkBL.jpg',
            productname: "Pinar Wine top",
            productdetails: 'Lorem ipsum dolor sit amet, consectetur ',
            productPrice: '$200',
            oldPrice: '$400'
        }, {
            imgsrc: 'img/41IP6IopkBL.jpg',
            productname: 'Pinar Wine top',
            productdetails: 'Lorem ipsum dolor sit amet, consectetur',
            productprice: '$200',
            oldprice: '$400'

        }]

Although the card layout is displaying, the attributes like product name, price are not showing up. Any idea what could be wrong?

Answer №1

Choosing the right names in programming is crucial to avoid confusion while working on your code. It's essential to carefully review your code for any inconsistencies.

This section is particularly important:

<card v-for= "products in product" :productname="product.productname"></card>
                                                       ^-- incorrect naming here

Instead of accessing product.productname, make sure you are referencing products.productname. Paying attention to these details can greatly impact the functionality of your program. Consider adjusting the naming conventions for clarity.

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

Uploading files seamlessly without the need for refreshing the page

On my HTML page, I have a form input that allows users to upload a file. Here is the code snippet: <form action = "UploadFile.jsp" method = "post" target="my-iframe" enctype = "multipart/form-data"> <input type = "file" name = "file" ...

Learning the process of accessing a JSON file from a different directory

I am faced with a straightforward folder structure, it looks like this: project │ └───data │ file.json │ └───js test.js My goal is to access the content of file.json within the test.js file in order to perform some ...

conditional rendering in a cascading sheet

Can the v-if directive be used within a style block in this manner? <style lang="scss" v-if="pinkTheme"> .ac-textfield { background: hotpink; } </style> I attempted to implement this, but unfortunately it did not work (the v-if directive ...

What are the differences in how a link tag responds on mobile devices?

I have a question regarding opening a pdf in an iframe on the current page. Is there a way to handle this differently for mobile/tablet users? For example, clicking the link could open it in another tab for better readability instead of within the iframe ...

Seeking assistance for my dissertation assignment: electron, express, and SQLite3

I am currently dedicated to my thesis project, which involves designing an educational desktop video game for both public and private schools within my city. Being a fan of electron, I thought it would be a great idea to develop my app using this platform ...

Errors encountered while running `npm install discord.js`

I am currently facing an issue while trying to install discord.js. Unfortunately, I keep encountering the following errors: npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR! <https://npm.co ...

Tips for preventing the loss of ajax calls when an Oauth access-token expires

As the creator of a JavaScript browser application (SPA) that communicates with a server protected by OAuth 2, I encounter the challenge of using short-lived access tokens and longer-lived refresh tokens. While this specific scenario involves my own server ...

Passing the title of a page as data to a component in Next.js

I am currently working on setting a custom title for each page within my next.js project. Here is an example of a simple Layout: const MainLayout = props => { return ( <Layout style={{ minHeight: "100vh" }}> <Head> < ...

Guide to automatically sending users to a subdomain depending on their IP address location

Currently, my website is built using Node Express and I have a specific requirement. I want to redirect users to different subdomains based on their current location. For example, if a user in Singapore accesses site.com, they should be redirected to sg. ...

"Discover the best way to sort through an array of complex objects with varying levels of nesting using a specified search

I have come across similar answers, but none of them go beyond two levels deep. Therefore, I believe this is not a duplicate problem. My task is to filter an array of objects where each object may contain nested objects of unknown depth. In my data structu ...

Initiate the countdown when the button is pushed

Recently ran into an issue where a button triggers a command to a Perl script, causing the page to continuously load for 60 seconds. To provide users with transparency on when the Perl script will be finished running, I implemented a JavaScript countdown t ...

Encountered an error in NodeJs with mongoDB: TypeError stating that property 'fullname' is not defined

I am having issues storing user-entered data from an HTML form into MongoDB. The error message I receive is "TypeError: cannot read property 'fullname' of undefined" TypeError: Cannot read property 'fullname' of undefined at C:&bso ...

The Node.js callback is executed before the entire function has finished executing

const fileSystem = require('fs'); const filePath = require('path'); module.exports.getFiles = function(filepath, callback) { let files = []; fileSystem.exists(filepath, function(exists){ if(exists){ fileSy ...

Retrieve the data object in VueJS

(Regarding a currency conversion tool) In order to accurately convert currencies, I am looking to access an object structured like this: rates: AUD: 1.708562 SGD: 1.546211 When retrieving these rates from an API, they are not always in the desired o ...

Starting the Android System Magnifier with a Click: A Step-by-Step Guide

Is there a way to incorporate a magnifying glass into an HTML page using jQuery or within an Android app? Ideally, it would be for a single picture. In my application, I am displaying an HTML file from my assets in a webview. The HTML page utilizes jQuery ...

Understanding the application of JSON data can be simplified by following these

I am looking to manipulate dates by either adding or subtracting them, but I am unsure of how to extract the dates from the other data present. var fetch = require('node-fetch'); fetch('https://api.nasa.gov/planetary/earth/assets?lon=100.7 ...

How do you send a variable in a GET request with React?

My challenge is to retrieve data from a table where the teacherId matches the teacherId of the user who logs in, but I am facing difficulties in passing this teacherId from the front-end to the back-end. Below is the backend code: app.get("/api/get&q ...

Utilize jQuery to seamlessly transfer each recorded audio file from rows to corresponding input fields within the table

I have a table below with 2 rows but it can be doubled with a button (Add another Word media) and only one submit button for all rows: <tbody> <tr class="form-row dynamic-medias" id="medias-0"> <td class=&quo ...

Encountering difficulty invoking a component method from d3's call() function

My current setup involves using D3 to drag and drop links in the following manner: .call(d3.drag() .on("start", linkDragStart) .on("drag", linkDragging) .on("end", linkDragEnd)); Recently, I decided to extract this functionality into a separate met ...

Begin by introducing a fresh attribute to a JSON entity

Looking for help with modifying JSON data: var myVar = { "9":"Automotive & Industrial", "1":"Books", "7":"Clothing" }; I need to insert a new element at the beginning of the array, resulting in this: var myVar = { "5":"Electroni ...