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

233
Visualizações
How to Allow Multiple Exports from a Vue3 Single File Component?

I'm making a Vue3 Single File Component for a custom list. In my single file component, I want to export the main default Vue component, but also the enum declaring what type of list it is:

child:

<template>
  <Listbox>
    <template #header>
      <h5>{{listType}}</h5>
    </template>
  </Listbox>
</template>

<script lang="ts">
export enum PagesListType {
  RecentlyCreated = 'Recently Created',
  RecentlyModified = 'Recently Modified',
  Starred = 'Starred'
};

export default {
  props: {
    listType: PagesListType
  },
  data() {
    return {
      pages: [],
      PagesListType
    };
  },
};

</script>

The enum only makes sense within the context of this component, so I don't want to put it in some other folder of types. It only relates to the behavior of this list. But when I try to do this in the parent component, it fails:

parent:

<template>
  <div>
    <PagesList :listType="PagesListType.RecentlyCreated"></PagesList>
    <PagesList :listType="PagesListType.RecentlyModified"></PagesList>
    <PagesList :listType="PagesListType.Starred"></PagesList>
  </div>
</template>

<script lang="ts">
import PagesList, { PagesListType } from './PagesList.vue';

export default {
  //parent component details
};
</script>

When I import the named PagesListType enum, it is just undefined. What do I need to do to export the named enum correctly? Thanks!

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

0

I opine you need to export enum into a separate file and import it in different files to use it. Where do you put this file depends on you mainly, how you want to structure your project.

For instance, types.ts file in the src folder can define and export the enum like:

export enum PagesListType {
  RecentlyCreated = 'Recently Created',
  RecentlyModified = 'Recently Modified',
  Starred = 'Starred'
}

you can use the enum anywhere by importing it like:

import { PagesListType } from '@/types';

you have to use @/ instead of src/. because of the src folder to @ in your TypeScript configuration available in the tsconfig.json file.

about 4 years ago · Juan Pablo Isaza Relatório

0

I was able to kinda get this to work by not exporting the enum, but adding it as a property to the exported default component:

child:

enum PagesListType {
  RecentlyCreated = 'Recently Created',
  RecentlyModified = 'Recently Modified',
  Starred = 'Starred'
};

export default {
  props: {
    listType: PagesListType
  },
  PagesListType,
  data() {
    return {
      pages: [],
      PagesListType
    };
  },
};

parent:

<template>
  <div>
    <PagesList :listType="created"></PagesList>
    <PagesList :listType="modified"></PagesList>
    <PagesList :listType="starred"></PagesList>
  </div>
</template>

<script lang="ts">
import PagesList from './PagesList.vue';

export default {
  computed: {
    created() {
      return PagesList.PagesListType.RecentlyCreated;
    },
    modified() {
      return PagesList.PagesListType.RecentlyModified;
    },
    starred() {
      return PagesList.PagesListType.Starred;
    }
  },
//other parent implementation details omitted
};
</script>
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