2021-08-08 05:47:29 +00:00
|
|
|
export default {
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-08-12 14:17:20 +00:00
|
|
|
system: (window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light",
|
2021-08-08 05:47:29 +00:00
|
|
|
userTheme: localStorage.theme,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
// Default Light
|
|
|
|
if (! this.userTheme) {
|
|
|
|
this.userTheme = "light";
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.classList.add(this.theme);
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
theme() {
|
|
|
|
if (this.userTheme === "auto") {
|
|
|
|
return this.system;
|
|
|
|
}
|
|
|
|
return this.userTheme;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
userTheme(to, from) {
|
|
|
|
localStorage.theme = to;
|
|
|
|
},
|
|
|
|
|
|
|
|
theme(to, from) {
|
|
|
|
document.body.classList.remove(from);
|
|
|
|
document.body.classList.add(this.theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|