vue.js 2 how to watch store values from vuex

后端 未结 18 2222
傲寒
傲寒 2020-11-27 10:26

I am using vuex and vuejs 2 together.

I am new to vuex, I want to watch a store variable change.

I want t

18条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 11:09

    When you want to watch on state level, it can be done this way:

    let App = new Vue({
        //...
        store,
        watch: {
            '$store.state.myState': function (newVal) {
                console.log(newVal);
                store.dispatch('handleMyStateChange');
            }
        },
        //...
    });
    

提交回复
热议问题