Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

Watch not watching

here is my computed and watch methods in my App.vue

computed: {
    ...mapState({
      autoLogout: (state) => state.autoLogout,
    }),
  },
  watch: {
    autoLogout(curValue, oldValue) {
      console.log("curVal and oldVal", curValue, oldValue);
      if (curValue && curValue != oldValue) {
        console.log("redirect to login");
        this.$router.replace("/login");
      }
    },
  },

nothing is being logged in the console, yes autoLogout state is changing from false to true but the watch is not triggering?!

0 likes
6 replies
Niush's avatar

Try this:

watch: {
    autoLogout: {
        handler: function (curValue, oldValue) {
          console.log("curVal and oldVal", curValue, oldValue);
        },
        deep: true // <-
    }
}
1 like
boyjarv's avatar

My fault, I put: state.autoLogout not state.auth.autoLogout

Please or to participate in this conversation.