Я пытаюсь передать эти данные компоненту в vue. Я могу получить данные в дочернем компоненте и отрендерить массив или получить доступ к свойствам каждого объекта, вызвав products[0].name
, но я хочу визуализировать каждый объект отдельно в v-for
l oop. пожалуйста, помогите !!
родительский компонент:
<template>
<div>
<h1>Welcome To Our Shop</h1>
<div class="products">
<div v-for="product in products" v-bind:key="product.name">
<div><ShopItem v-bind:products="products" /></div>
</div>
</div>
</div>
</template>
<script>
import ShopItem from "../components/Shop/ShopItem";
export default {
name: "Shop",
components: { ShopItem },
data() {
return {
products: [
{
name: "Basic Deck",
price: 7,
description:
"The Basic Deck includes 68 cards: 10 cards in each of six categories, three icon legend cards, five blank cards for developing your own backstory elements, and instructions.",
image: require("@/assets/Draeorc.png"),
},
{
name: "Card Bundle",
price: 10,
description:
"The Card Bundle includes the Basic Deck, Technical Booster, Mystical Booster and instructions as a single self-printable PDF.",
image: require("@/assets/Twilight.png"),
},
{
name: "Full Bundle with Box",
price: 12,
description:
"The Full Bundle includes the Basic Deck, Technical Booster, Mystical Booster, instructions and tuck box as a single self-printable PDF.",
image: require("@/assets/Orig_Godbringer.png"),
},
],
};
},
};
</script>
дочерний компонент:
<template>
<div class="product-container">
<div>
<h2>{{ products[0].name }}</h2> //this is where I want to call on the name
<div class="card-container">
<img src="../../assets/Draeorc.png" alt="cards" />
</div>
</div>
</div>
</template>
<script>
export default {
name: "ShopItem",
props: ["products"],
};
</script>