Jonny Preis
New Coder
Hello im trying to get my Dark mode working but i cant find the problem
Maybe you can help me find the problem
ty
JavaScript:
<template>
<!--<v-btn @click="toggleTheme" text rounded outlined>Change Mode</v-btn>
--><v-btn icon @click="toggleTheme" v-on:keyup="emitToParent">
<v-icon >
{{ ($vuetify.theme.dark) ? 'mdi-weather-night' : 'mdi-weather-sunny' }}
</v-icon>
</v-btn>
</template>
<script>
export default {
data() {
return {
dark: null,
darkmode: null,
}
},
methods: {
toggleTheme() {
if(this.darkmode[0].force){
this.dark = true;
this.emitToParent();
this.$vuetify.theme.dark = true;
localStorage.setItem("dark_mode", this.$vuetify.theme.dark.toString());
}else{
this.$vuetify.theme.dark =false;
localStorage.setItem("dark_mode", this.$vuetify.theme.dark.toString());
this.dark = this.$vuetify.theme.dark;
this.emitToParent();
//console.log(this.$vuetify.theme.dark);
}
},
emitToParent () {
this.$emit('childToParent', this.dark)
},
getData(){
this.axios
.post(this.$baseURL_Avancis + '/backend/sideDrawer.php')
.then(response => (
this.darkmode = response.data.darkmode,
this.force()
//,console.log(this.darkmode[0].force)
))
},
startup(){
const theme = localStorage.getItem("dark_mode");
if (theme) {
if (theme == "true") {
this.dark = true;
this.emitToParent();
this.$vuetify.theme.dark = true;
} else {
this.dark = false;
this.emitToParent();
this.$vuetify.theme.dark = false;
}
}
}
},
mounted() {
this.getData()
this.startup()
},
};
</script>
Maybe you can help me find the problem
ty