vuex订阅个别突变

Chr*_*ris 14 javascript vue.js vuex

是否有可能订阅个别突变?

代替:

this.$store.subscribe((mutation, state) => {
   if(mutation === 'someMutation'){
       doSomething()
   }
})
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

this.$store.subscribe('someMutation', state => {
    doSomething()
})
Run Code Online (Sandbox Code Playgroud)

小智 -5

尝试这样的事情:

this.$store.subscribe(mutation => {
                if (mutation.type === 'setData') {
//  do something here
                }
            });
Run Code Online (Sandbox Code Playgroud)

  • 这与我已经在做的几乎相同。(即我的问题中的第一个代码示例)。我正在寻找像第二个示例这样的解决方案 (3认同)