mardi 19 janvier 2021

VueJs - Vuex - Change a state

i want to change the state "mode" to "" with a switch from Vuetify.

This is my store/index.js.

export default new Vuex.Store({
  state: {
    mode: 'dark',
  },
  mutations: {
    change (state) {
      state.mode += '';
    }
  },
  actions: {
  },
  modules: {
  }
}) 

This is my Vue Code (Only snippets)

<v-switch
          v-model="switch1"
          :label="`Dark / Light Mode: ${switch1.toString()}`"
        ></v-switch>

<script>
export default {
  data () {
    return {
      switch1: true,
    }
  },
  watch : {
    switch1(newValue) {
      this.$store.commit('change');
      console.log(newValue);
    }
  }
    
}
</script>

I am a newbie. Is this the right method to do this? Or is a easy way to make this?

Cheers




Aucun commentaire:

Enregistrer un commentaire