Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

dynamically products shows another "product" that is not exist in vue3

my code is:

ShopView.vue

<template>
    <div class="Shop">
        <h1>Shop</h1>
        <h2>Products</h2>
        <div class="products" v-for="Products in products" :key="Products.id">
            <ul>
                <li>{{ Products.name }}</li>
                <li><img :src="Products.pic" /></li>
                <li>Price: ${{ Products.price }}</li>
            </ul>
        </div>
    </div>
</template>

<script>
import Products from "../../data/products.json"

export default {
    name: "Shop",
    data() {
        return {
            products: Products,
        }
    }
}
</script>

<style lang="scss" scoped>
.shop {
    font: 1em sans-serif;
    font-size: large;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-weight: bold;
}

.products {
    font-size: xx-large;
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    font-weight: bolder;
    font-style: italic;
}

ul {
    list-style-type: none;
}
</style>

products.json

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  "Products",
  {
    "id": "1",
    "pic": "apple.jpg",
    "name": "Apple",
    "description": "good fruit",
    "price": 9.99
  },
  {
    "id": "2",
    "pic": "banana.jpg",
    "name": "Banana",
    "description": "Healthy fruit",
    "price": 5.99
  }
]

how do I remove this "empty" product that is not actually exist in my "db"(products.json)?

here is the error below(I marked the error in black(which is shows only a "price" of a product but it’s not actually exists)):

enter image description here

>Solution :

Remove "Products" from products.json.
After removing "Products" from products.json, it would look like

products.json

[
  {
    "id": "1",
    "pic": "apple.jpg",
    "name": "Apple",
    "description": "good fruit",
    "price": 9.99
  },
  {
    "id": "2",
    "pic": "banana.jpg",
    "name": "Banana",
    "description": "Healthy fruit",
    "price": 5.99
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading