We will use the VueUse
you can Read the Docs here VueUse
What's the VueUse ?
VueUse is a collection of hundreds of essential Vue Composition Utilities for interacting with various browser, sensor, animation, and state apis, plus more!
In this Topic, we’ll sample some hand picked functions from each category to give you an idea of what’s possible with VueUse and hopefully wet your appetite to utilize VueUse in your own projects.
let Start install the VueUse
npm i @vueuse/core
then will use one of the Utilities named useDark
we will import the Utilities into our component
import { useDark, useToggle } from '@vueuse/core'
And will Define them as Variables
const isDark = useDark() // True of False
const toggleDark = useToggle(isDark)
the isDark will give us the Boolean result True or False but by defualt will be False
<template>
<div>{{isDark}}</div>
</template>
we will see the output
Then we will use the toggleDark Button to switch between true or false
<button @click="toggleDark()">
Is Dark: {{ isDark }}
</button>
when we toggle between the Dark mode the useDark add variable in LocalStorage named vueuse-color-scheme
the value by default (false) is Auto
and when toggle (true) will be dark
also useDark add class to HTML tag
<html lang="en" class="dark">
Now we can add Style for Dark Mode
.dark {
background: #252525;
color: #fff;
}
you can see how the Dark mode is applied
🤩 🥳 WOW now you have an Easy Dark Mode Applied in less Than one Minute💪
Follow Me in Linkedin ☺️ 😊 😇
Thanks For Reading My Topic waiting for More topic in VueUse☺️ 😊 😇
Top comments (0)