Skip to content

Commit bb61252

Browse files
committed
Set dark when prefer-color-scheme is configured
1 parent 5bea894 commit bb61252

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

demo/index.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h1>
6666
VueDarkMode by CSS Filters
6767
</h1>
6868
<div>
69-
<vue-dark-mode :is-dark="preferDark">
69+
<vue-dark-mode>
7070
<template v-slot="{ mode }">
7171
Dark mode: {{ mode ? 'on' : 'off' }}
7272
</template>
@@ -90,12 +90,7 @@ <h1>
9090

9191
<script>
9292
new Vue({
93-
el: '#app',
94-
computed: {
95-
preferDark: function () {
96-
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
97-
}
98-
}
93+
el: '#app'
9994
})
10095
</script>
10196
</body>

src/vue-dark-mode.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export default {
4848
darkMode: this.isDark
4949
}
5050
},
51+
created () {
52+
if (!this.$isServer) {
53+
this.darkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches
54+
}
55+
},
5156
methods: {
5257
toggleDarkMode () {
5358
this.darkMode = !this.darkMode

0 commit comments

Comments
 (0)