Light theme/Dark theme toggle with Nuxt 2 & Vuetify

PHOTO EMBED

Wed Nov 03 2021 10:46:19 GMT+0000 (UTC)

Saved by @desiboli ##javascript ##js #nuxt.js #nuxt #vue #vue.js

  mounted() {
    const theme = localStorage.getItem('useDarkTheme');
    if (theme) {
      if (theme == 'true') {
        setTimeout(() => {
          this.$vuetify.theme.dark = true;
        }, 0);
      } else {
        setTimeout(() => {
          this.$vuetify.theme.dark = false;
        }, 0);
      }
    } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
      setTimeout(() => {
        this.$vuetify.theme.dark = true;
      }, 0);
    }
  }
content_copyCOPY