0

I'm new to vue.js and I want to create some product cards that will dynamically set its attributes through vue.js:

I have this is my HTML snippet:

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

This is my vue.js template/componet code:

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 this is my vue instance:

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'

        }]

But it's just displaying the cards, the attributes (e.g. product name, price etc.) are not displaying. What am I doing wrong?

0

1 Answer 1

2

Naming is really important in development to not get confused by what you've been writing. Take a look at your code.

Especially here

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

You are accessing product.productname but you want to access products.productname. As I said, naming is important. You might change the naming for product and products.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.