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

132
Visualizações
Is there a way to destructure vue props so I don't have to pass every single one in?

Simply put, I have a component

<Device>
v-for="device in devices" 
:key="device.name"
:device="device"
:name="device.name"
:number="device.number"
:type="device.type"
:status="device.status"
:plan="device.plan"
:plan_price="device.plan_price"
:health="device.health"
</Device>

I then define them in the props section of the component

props: {
        type: { type: String, default: "" },
        number: { type: String, default: "" },
        name: { type: String, default: ""},
        plan: { type: String, default: "" },
        plan_price: { type: String, default: "" },
        status: { type: Number, default: 0 },
        health: { type: Number, default: 0 },
    },

I am just wondering if there is a way to pass in :device="device" without having to pass in every individual property. I also wanted to avoid having to use device.name device.property in the template within the component Thank you for any tips!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use v-bind to achieve some kind of object destructuring for props.

<Device>
  v-for="device in devices" 
  :key="device.id"
  v-bind="device"
</Device>
props: {
  type: { type: String, default: "" },
  number: { type: String, default: "" },
  name: { type: String, default: ""},
  plan: { type: String, default: "" },
  plan_price: { type: String, default: "" },
  status: { type: Number, default: 0 },
  health: { type: Number, default: 0 },
}

Demo: https://stackblitz.com/edit/vue-jngtah?file=src/App.vue

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