Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Vue Props passed to SFC end up as attributes in DIV element

I trying to pass an object to a child component. The object is from a fetch request to Strapi. I'm using Nuxt Bridge and Vue 2.6.14

The fetch in the parent

<script>
export default {

    async fetch() {
        this.featured = await fetch(
            'http://localhost:1337/api/getFeature',
        ).then((res) => res.json());

        this.feed = await fetch(
            'http://localhost:1337/api/getFeed'
        ).then((res) => res.json());
             
    },
    data(){
        return {
            featured: {},
            feed: []
                     }
        
    },

}
</script>

The component

<Feature v-bind="featured"/>

In the child component

<script>
export default {
    props: {
        featured:Object,
    }
}
</script>

The problem is that the object ends up as attributes on the first div tag in the child component.

<div title="Apple pie apple pie tootsie roll liquorice tiramisu topping" lede="Gummies lemon drops tootsie roll cake jelly beans candy cotton candy. Apple pie chocolate bar bear claw icing candy chocolate bar jelly pie" url="https://ik.imagekit.io/nnydigital/strapi/bryam_blanco_n_XKW_Ln8y9q_E_unsplash_44c4203534_M_Kx22_N6x_YD_abf84d3bbd_Mo5JvpCD3.jpg" created="Wed Jun 29 2022 10:38:07 GMT-0400 (Eastern Daylight Time)" updated="Wed Jun 29 2022 10:38:08 GMT-0400 (Eastern Daylight Time)" published="Wed Jun 29 2022 10:38:08 GMT-0400 (Eastern Daylight Time)">

If use <Feature :title="featured.title" />

It works as expected. What am I missing/doing wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Yes, v-bind will spread the object properties.

So the child component props will not contain the featured object, but it will contain all its properties and it will bind it to the main element of the component, and the props will be like that.

<script>
export default {
    props: {
        title: string,
        lede: string,
        url: string,
        created: string,
        updated: string,
        published: string,
    }
}
</script>

If you want to send featured object itself, then you need to go with

<Feature :featured="featured"/>

Then you can get it from props like that

<script>
export default {
    props: {
        featured:Object,
    }
}
</script>
about 4 years ago · Juan Pablo Isaza Report

0

According to your <Featured/> component there is only a featured prop.

to be able to pass title and others you need to add them in the props section of the component like this

<script>
export default {
    props: {
        published: string,
        title: string,
        lede: string,
        url: string,
        updated: string,
        created: string,
    }
}
</script>

else you will just pass the whole object at once and use it like this this.props.title

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!