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

304
Vistas
How to expect and pass in enum as a component property?

I created a Vue 3 app using TypeScript. Inside the src folder I created a new enum color.ts

enum Color {
    Red,
    Blue
}

export default Color;

I created a component ColorDisplay.vue

<template>
  <div>
    {{ color }}
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import Color from "../color";

export default defineComponent({
  props: {
      color: {
          type: Color,
          required: true
      }
  }
});
</script>

and modified the Home.vue file to

<template>
  <div>
    <color-display :color="Color.Red" />
    <color-display :color="Color.Blue" />
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import ColorDisplay from "../components/ColorDisplay.vue";
import Color from "../color";

export default defineComponent({
  components: {
    'color-display': ColorDisplay,
  }
});
</script>

Unfortunately several problems come up:

  • In Home.vue the imported Color is unused although I'm trying to use it in the template
  • In ColorDisplay.vue the enum seems to be an invalid prop type

enter image description here

Would someone mind telling me how to create an enum, expect it as a component property and pass it to components?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Component prop type value is restricted to builtin constructors and custom classes. TS enums are not classes but objects with specific types and can't be used as is with type.

It likely should be:

  color: {
      type: Number as PropType<Color>,
      required: true
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try annotating the properties with a PropType. Object as PropType

Here the VueJS 3 Documentation for Annotating Properties: https://v3.vuejs.org/guide/typescript-support.html#annotating-return-types

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