Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda