Skip to content

Commit 63488d6

Browse files
committed
Refactor: Check if the meta-theme-color was passed
1 parent 486ec47 commit 63488d6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Diff for: src/vue-dark-mode.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export default {
3636
},
3737
metaThemeColor: {
3838
type: Object,
39-
default () {
40-
return {}
41-
}
39+
default: () => ({})
4240
}
4341
},
4442
@@ -102,17 +100,19 @@ export default {
102100
this.chosenMode = chosenMode
103101
window[this.storage].setItem('colorMode', this.chosenMode)
104102
this.handleColorModeClass('add')
105-
this.setMetaThemeColor(this.metaThemeColor[this.currentMode] || this.metaThemeColor[this.getPrefersColorScheme] || '#fff')
103+
if (Object.keys(this.metaThemeColor).length) this.setMetaThemeColor(this.metaThemeColor[this.currentMode] || this.metaThemeColor[this.getPrefersColorScheme])
106104
},
107105
108106
getMediaQueryList (type) {
109107
return window.matchMedia(`(prefers-color-scheme: ${type})`)
110108
},
111109
112110
setMetaThemeColor (color) {
113-
this.$nextTick(() => {
114-
if (this.elementMetaThemeColor) this.elementMetaThemeColor.setAttribute('content', color)
115-
})
111+
if (color) {
112+
this.$nextTick(() => {
113+
if (this.elementMetaThemeColor) this.elementMetaThemeColor.setAttribute('content', color)
114+
})
115+
}
116116
},
117117
118118
handleColorModeClass (action, cls) {

0 commit comments

Comments
 (0)