简体   繁体   English

如何将 href 参数从父 vue 组件传递给子组件?

[英]How to pass href parameter from parent vue component to child component?

Good evening, I'm trying to create a page in Vue, parsing it into components.晚上好,我正在尝试在 Vue 中创建一个页面,并将其解析为组件。 and rendering content using json, And it seems to be nothing complicated.并使用 json 渲染内容,看起来并不复杂。 but there is a problem?但有个问题? But why is the href parameter in the wrong place, Please tell me.但是为什么href参数在错误的地方,请告诉我。 I have been unable to solve this riddle for several hours.几个小时以来,我一直无法解开这个谜语。

index.vue索引.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英雄.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>

You probably forgot to define href as a prop in your Hero component.您可能忘记了将 href 定义为 Hero 组件中的道具。

Make sure you have added href as prop in your Hero component.确保你已经在 Hero 组件中添加了 href 作为 prop。


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

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM