Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda