close

[Solved] vue.js 2 how to watch store values from vuex

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error vue.js 2 how to watch store values from vuex in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How vue.js 2 how to watch store values from vuex Error Occurs?

Today I get the following error vue.js 2 how to watch store values from vuex in javascript.

How To Solve vue.js 2 how to watch store values from vuex Error ?

  1. How To Solve vue.js 2 how to watch store values from vuex Error ?

    To Solve vue.js 2 how to watch store values from vuex Error It's as simple as:
    watch: { '$store.state.drawer': function() { console.log(this.$store.state.drawer) } }

  2. vue.js 2 how to watch store values from vuex

    To Solve vue.js 2 how to watch store values from vuex Error It's as simple as:
    watch: { '$store.state.drawer': function() { console.log(this.$store.state.drawer) } }

Solution 1

It’s as simple as:

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

Solution 2

I think the asker wants to use watch with Vuex.

this.$store.watch(
      (state)=>{
        return this.$store.getters.your_getter
      },
      (val)=>{
       //something changed do something

      },
      {
        deep:true
      }
      );

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment