“Vuex Store Watch” Code-Antworten

Vuex Store Watch

import { mapState } from 'vuex';

export default {
    computed: {
        ...mapState(['somestate']),
        someComputedLocalState() {
            // is triggered whenever the store state changes
            return this.somestate + ' works too';
        }
    },
    watch: {
        somestate(val, oldVal) {
            // is triggered whenever the store state changes
            console.log('do stuff', val, oldVal);
        }
    }
}
Yawning Yak

Vuex Store Watch

watch: {
  '$store.state.drawer': function() {
    console.log(this.$store.state.drawer)
  }
}
Yawning Yak

Vuex Store Watch

computed: {
    ...mapState({
        // to access local state with `this`, a normal function must be used
        countPlusLocalState (state) {
          return state.count + this.localCount
        }
    }
})
Yawning Yak

Ähnliche Antworten wie “Vuex Store Watch”

Fragen ähnlich wie “Vuex Store Watch”

Weitere verwandte Antworten zu “Vuex Store Watch” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen