File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 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 >
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 >
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments