Home  >  Q&A  >  body text

Guide to sending props in Vue

<p>I'm still new to Vue, so I don't fully understand the logic yet. My problem is, I have a ticket and ticketlist components. So when I'm not in my ticket list component, I'm creating some tickets data, and I want to display them based on the ticket component. To make it clearer, this is my ticketlist component: </p> <pre class="brush:php;toolbar:false;"><template> <section class="tickets"> <div class="container"> <div class="row"> <div class="col-12 col-md-3 mb-3"> <Ticket v-for="ticket in tickets" :key="ticket.id" :product="ticket"/> </div> </div> </div> </section> </template> <script> import Ticket from './Ticket' export default { components: { Ticket }, data() { return { tickets: [ { id: 0, category: "Einzelkarte", price: "€3,50", tariff: [ "Wählen Sie eine Option", "Erwachsene", "Erwachsener erm.", "Kinder / Jugendliche", "Kinder / Jugendliche erm.", ], available_amount: 23, article_number: "2021.05.04-2673990197-1", }, ], }; }, } </script></pre> <p>There is also a ticket component: </p> <pre class="brush:php;toolbar:false;"><template> <widget type="ticket" class="--flex-column"> <div class="top --flex-column"> <div class="bandname -bold">Ghost Mice</div> <div class="tourname">Home Tour</div> <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/199011/concert.png" alt="" /> <div class="deetz --flex-row-j!sb"> <div class="event --flex-column"> <div class="date">3rd March 2017</div> <div class="location -bold">Bloomington, Indiana</div> </div> <div class="price --flex-column"> <div class="label">Price</div> <div class="cost -bold">€{{ ticket.price }}</div> </div> </div> </div> <div class="rip"></div> <div class="bottom --flex-row-j!sb"> <a class="btn button" href="#">ADD TO CART</a> </div> </widget> </template> <script> export default { props: ['ticket'], } </script> <style scoped> @import 'https://i.koya.io/flex/1.1.0.css'; *, ::after, ::before { box-sizing: unset; } </style></pre> <p>So, I'm displaying the TicketList component in a page, but the problem is that it's not displaying anything. So I want to know how to connect them together and display the tickets data based on the ticket component. I hope I made it clear, if not I can answer you in the comments. </p>
P粉166675898P粉166675898415 days ago430

reply all(1)I'll reply

  • P粉925239921

    P粉9252399212023-08-31 12:58:27

    The problem is with the names of the props, you need to pass ticket as props, not product

    ...
       <Ticket v-for="ticket in tickets" :key="ticket.id" :ticket="ticket"/>
    ...

    Or set it in your Ticket component:

    props: ['product']

    reply
    0
  • Cancelreply