Home > Net >  How to pass href parameter from parent vue component to child component?
How to pass href parameter from parent vue component to child component?

Time:04-09

Good evening! I'm trying to create a page in Vue, parsing it into components, and rendering content using json. And it seems to be nothing complicated, but there is a problem. But why is the href parameter in the wrong place? Please tell me, I have been unable to solve this riddle for several hours.

index.vue

<template>
  <section>
    <Hero
      v-for="(hero, index) in heroes"
      :title="hero.title"
      :description="hero.description"
      :more="hero.more"
      :href="hero.href"
      :key="index"
    />
  </section>
</template>

Hero.vue

<template>
  <div>
    <h2>{{ title }}</h2>
    <p>{{ description }}</p>
    <a :href="href">{{ more }}</a>
  </div>
</template>
<script>

Result

<section>
  <div href="/create">
    <h2>Create and share your photo stories.</h2>
    <p>
      Photosnap is a platform for photographers and visual storytellers. We make
      it easy to share photos, tell stories and connect with others.
    </p>
    <a>Get an Invite </a>
  </div>
  ...
</section>

CodePudding user response:

You probably forgot to define href as a prop in your Hero component.

Make sure you have added href as prop in your Hero component.


  props: {
    href: {
        type: String,
        required: true
     }

  }

  • Related