Guide on transferring href parameter from the parent Vue component to the child component

Hey there! I've been working on creating a Vue page, breaking it down into components, and populating it with content from json. It all seems pretty straightforward, but I've hit a snag. Why is the href parameter not showing up in the right place? It's been puzzling me for hours now. Can anyone provide some insight?

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>

Answer №1

It seems like you may have overlooked defining href as a prop in your Hero component.

Don't forget to include href as a prop within your Hero component.


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

  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to incorporating nested loops with the map method in React JS

I've come across numerous threads addressing the nested loop using map in React JS issue, but I'm still struggling to implement it in my code. Despite multiple attempts, I keep encountering errors. Here are some topics I've explored but cou ...

Is React the ideal choice for implementing a shared state subscription mechanism in your project?

Trying to determine if this falls under the "pub/sub" pattern or a variation of it. The goal is to establish a shared state where different components can subscribe to it and only receive updates when the state changes. const useForceUpdate = () => useR ...

Can you explain the purpose of the child-flex option within a v-flex component in Vuetify?

Reviewing the Vuetify online documentation regarding Grid Systems and Unique Layouts, it was noted that the v-flex tag used for the Orange block includes a child-flex parameter. <v-flex d-flex xs12 sm2 child-flex> <v-card color="orange l ...

I am attempting to extract text from an element, but instead of the text, I received a value and am unable to click on it. This particular element is a dropdown button in a Selenium test, with

<div class="select-wrapper initialized"> <span class="caret">▼</span> <input type="text" class="select-dropdown" readonly="true" data-activates="select-options-56a6924e-42d9-1f78-1b82-fe2c1cbdfbdd" value="R3PORTS ...

Issue with migration from Vue2 to Vue3: Transition animations malfunctioning

Currently, I am in the process of migrating a project from Vue2.7 to Vue3 and vite. In order to maintain compatibility with the compositionAPI support in 2.7, I essentially replicated the existing code. However, after the migration, I noticed that the tran ...

Showing various SQL data fields within a single HTML column

I am facing a challenge with displaying multiple checkboxes from different columns in a database as a single column on a webpage. Here is the HTML form structure: <div class="form-group"> <label class="col-md-2 control-label">R-1 ...

Angular Material: creating a custom sidenav transition from detailed layouts to icon-based designs seamlessly without the need for predefined

I'm currently working on a <sidenav> that has the ability to toggle between displaying text along with icons or just icons using a menu button. The <sidenav-content> section is set to automatically resize with a smooth transition effect. ...

Exploring Unanchored Substring Queries in Loopback API

Searching for a solution to implement a basic substring query using the loopback API for a typeahead field. Despite my efforts, I have not been able to find a clear answer. I simply want to input a substring and retrieve all brands that contain that subst ...

Tips for repositioning a child div to the top upon detecting a text change

I am working with a parent div that contains 3 child divs. I am curious if there is a way to automatically move a child div to the top if any changes are made to its text or link? <div id="latest"> <div class="post post-1"><a href="#"> ...

Tips for positioning an image, text, and button horizontally without resorting to tables

Does anyone know how to align a movie poster image, description text, and add to cart button on the same line? The text must be centered aligned without wrapping around the button or image, just like in this example. https://i.sstatic.net/yQaCl.png Curre ...

Looking for a solution to resolve the issue "ERROR TypeError: Cannot set property 'id' of undefined"?

Whenever I attempt to call getHistoryData() from the HTML, an error message "ERROR TypeError: Cannot set property 'id' of undefined" appears. export class Data { id : string ; fromTime : any ; toTime : any ; deviceType : string ...

What is the method for configuring automatic text color in CKEditor?

https://i.sstatic.net/yEM3p.png Is there a way to change the default text color of CKEditor from #333333 to #000000? I have attempted to modify the contents.css in the plugin folder: body { /* Font */ font-family: sans-serif, Arial, Verdana, "Tr ...

Modifying line height with Jquery

Looking for help with my html code. I have a <div id="listview"> element with an unordered list inside containing a list item that has its height dynamically set using inline CSS. I'm trying to change the height of the list item using jQuery, bu ...

I am looking to pair a unique audio clip with each picture in my collection

I have implemented a random slideshow feature that cycles through numerous images. I am now looking to incorporate a brief audio clip with each image, synchronized with the array I have established for the random pictures. The code snippet below is a simil ...

Errors occur when attempting to install plugins from npm

I am currently coding in Visual Studio 2017 using Ionic v2 to develop an app for beacon scanning. However, every time I try to install a plugin, I encounter errors from npm about the versions of node and npm being incompatible. Here are my current versions ...

Creating dynamic SVG animations through CSS instead of relying on the <animateMotion> tag offer greater flexibility and control

I am attempting to position an arrow at the midpoint of a bezier curve. The method outlined in this StackOverflow question, which involves using <animateMotion> to move a <path> representing the arrow and freezing it at the center of the curve, ...

Embedding a YouTube video in a view player using HTML5

So I've got a question: can you actually open a youtube video using an HTML5 video player? I'm looking for a more mobile-friendly way to watch youtube videos, and my idea was to upload a thumbnail image and then set up an onclick function to disp ...

Verify the accuracy of quiz responses with PHP and AJAX

I am working on a picture quiz that has one input field for each image. I am looking for a solution to verify if the value entered into the input field matches the correct answer. If it does match, I need to perform certain operations like adding or removi ...

Error: Uncaught ReferenceError: d3 is undefined. The script is not properly referenced

Entering the world of web development, I usually find solutions on Stack Overflow. However, this time I'm facing a challenge. I am using Firefox 32 with Firebug as my debugger. The webpage I have locally runs with the following HTML Code <!DOCTYP ...

Transitioning the width in CSS without using the "auto"

Currently, I am experiencing a problem with my CSS animation that is leaping directly from the start to finish. It appears to be connected to a similar issue addressed in this thread. My inquiry is: Is there a way to create a smooth transition in width f ...