Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

<NuxtLayout> name prop not reactive

I have a component that should switch the used layout based on the current breakpoint.

<script setup lang="ts">
import { computed } from "vue";
import { breakpointsTailwind } from "@vueuse/core";

const breakpoints = useBreakpoints(breakpointsTailwind);

const layoutName = computed(() =>
  breakpoints.smaller("md") ? "sidenav-mobile" : "sidenav-desktop",
);
</script>

<template>
  <div>
    {{ breakpoints.smaller("md") }} <!-- this is reactive -->
    <NuxtLayout :name="layoutName"> <!-- layoutName is not reactive -->
      <template #links>
        <slot name="links"></slot>
      </template>
    </NuxtLayout>
  </div>
</template>

When resizing the window below or above the breakpoint, my debug output {{ breakpoints.smaller("md") }} correctly changes to true or false, but the layout does not switch unless I reload.

What am I doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It returns a ref. In templates they’re unwrapped, so it works "as expected".

In your computed you need to add a .value to read the current value.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading