Skip to content

Commit

Permalink
chore: 暗黑模式全由 vue-dark-switch 实现
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Jun 9, 2023
1 parent bb51a1a commit 370488a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,45 +670,22 @@ pnpm add naive-ui

<br />

### [12. 暗黑模式支持](https://cn.windicss.org/features/dark-mode.html#dark-mode)
### [12. 暗黑模式支持](https://github.com/dishait/vue-dark-switch)

暗黑模式由 的 [vue-dark-switch](https://github.com/dishait/vue-dark-switch)
`VueUse` 实现。

`src/composables` 目录用来存储 `composition-api` 模块。

该目录下预设了`useDarks` 模块,该模块导出 `isDark``toggleDark`
用来显示和切换暗黑模式。

```ts
// src/composables/useDarks.ts

// vueuse的 api 会自动按需引入,无需import
export const isDark = useDark();
export const toggleDark = useToggle(isDark);

export const useDarks = () => ({ isDark, toggleDark });
```

模板中即可直接用
暗黑模式由 [vue-dark-switch](https://github.com/dishait/vue-dark-switch) 实现。

```html
<script setup lang="ts">
import { useDarks } from '../composables/useDarks'
const { isDark, toggleDark } = useDarks()
<script setup>
import { SwitchIcon } from "vue-dark-swicth"
</script>

<template>
<div m="6">Hello,This is the tov template!!</div>
<div m="6" cursor="pointer" @click="toggleDark()">
light: {{ isDark }} click me!!
</div>
<!-- 暗黑 switch,一键切换暗黑模式 -->
<SwitchIcon />
</template>
```

具体可见 👉 [vue-dark-switch](https://github.com/dishait/vue-dark-switch)
[vueuse/usedark](https://vueuse.org/core/usedark/#usedark)
具体可见 👉 [vue-dark-switch](https://github.com/dishait/vue-dark-switch)

<br />

Expand Down
4 changes: 0 additions & 4 deletions src/composables/useDarks.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/pages/echarts.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { use } from 'echarts/core'
import { isDark } from 'vue-dark-switch'
import { PieChart } from 'echarts/charts'
import { CanvasRenderer } from 'echarts/renderers'
import {
Expand All @@ -17,8 +18,6 @@ use([
LegendComponent,
])
const { isDark } = useDarks()
provide(
THEME_KEY,
computed(() => (isDark.value ? 'dark' : ''))
Expand Down

0 comments on commit 370488a

Please sign in to comment.