English | Chinese
Dark mode switch is a commonly used feature in projects. To reduce the workload for future projects, this component is encapsulated.
- Beautiful
- Ready to use
- Supports manual operation
- naive-ui support
npm i vue-dark-switch
<script setup>
import { Switch } from "vue-dark-switch"
</script>
<template>
<Switch />
</template>
Customize Switch
background color
<template>
<Switch darkBackground="#fff" lightBackground="#2D2D2D" />
</template>
<script setup>
import { Switch } from "vue-dark-switch"
import WorkspacePremiumTwotone from "@vicons/material/es/WorkspacePremiumTwotone"
import WorkspacePremiumOutlined from "@vicons/material/es/WorkspacePremiumOutlined"
</script>
<template>
<Switch>
<template #dark>
<WorkspacePremiumOutlined />
</template>
<template #light>
<WorkspacePremiumTwotone />
</template>
</Switch>
</template>
<script setup>
import { SwitchIcon } from "vue-dark-switch"
</script>
<template>
<SwitchIcon />
</template>
<script setup>
import { SwitchIcon } from "vue-dark-switch"
import WorkspacePremiumOutlined from "@vicons/material/es/WorkspacePremiumOutlined"
import WorkspacePremiumTwotone from "@vicons/material/es/WorkspacePremiumTwotone"
</script>
<template>
<SwitchIcon>
<template #dark>
<WorkspacePremiumOutlined />
</template>
<template #light>
<WorkspacePremiumTwotone />
</template>
</SwitchIcon>
</template>
// nuxt.config.ts
export default defineNuxtConfig({
build: {
transpile: ["vue-dark-switch"],
},
})
<script setup lang="ts">
import { Switch } from "vue-dark-switch"
</script>
<template>
<div>
<ClientOnly>
<Switch />
</ClientOnly>
</div>
</template>
import { isDark, toggleDark } from "vue-dark-switch"
isDark.value // Whether in dark mode
toggleDark(false) // Turn off dark mode
toggleDark(true) // Turn on dark mode
toggleDark() // Switch mode
<!-- App.vue -->
<script setup>
import { NConfigProvider } from "naive-ui"
import { naiveTheme } from "vue-dark-switch"
</script>
<template>
<n-config-provider :theme="naiveTheme">
<router-view />
</n-config-provider>
</template>
This component is built using the following libraries:
This component is supported by vue3-exports and vite-layers.
Made with markthree
Published under MIT License.