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

333
Vistas
How to get the current nuxt layout from within a component/template?

Nuxt provides a way to dynamically set a layout within a component, but is there a way to determine which layout is in use from within the <template> e.g. v-if="layout === 'me'"? For example, I want to use a single route /c/dream and provide one layout for a user who is authenticated and another layout for a user who is not authenticated. If I can determine the layout in use from within the template, then I can structure the HTML according to the layout. I've inspected the this object in a component and do not see a way to determine which layout is in use.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

One way is to rely on Vue provide/inject feature to pass down this information to all child components.

Your layouts would provide the name of the layout:

// layouts/authenticated.vue
export default {
  provide() {
    return { layout: "authenticated" };
  },
};

Your page components or any child component can inject layout to determine which layout is currently in use.

pages/c/dream.vue

<template>
  <div>
    <div v-if="layout == 'authenticated'">
      <!-- custom UI for authenticated users -->
    </div>
  </div>
</template>

<script>
export default {
  // Determines which layout is currently in use
  inject: ["layout"],

  // Decide which layout to use
  // based on Nuxt context as an example
  layout(context) {
    return context.user ? "authenticated" : "default";
  },
};
</script>

I have to admit, it's strange to implement layout(context) in order to set the layout we want to use and have to inject layout to access the value in the same component.

over 4 years ago · Santiago Trujillo 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