vuex使用小技巧

vuex表单处理

<input v-model="message">
// ...
computed: {
  message: {
    get () {
      return this.$store.state.obj.message
    },
    set (value) {
      this.$store.commit('updateMessage', value)
    }
  }
}

subscribe(handler: Function): Function

handler会在每一个 mutation 完成后调用,接收 mutation 和通过 mutation 后的状态做为参数:vue

store.subscribe((mutation, state) => {
  console.log(mutation.type)
  console.log(mutation.payload)
})
相似的还有subscribeAction方法

replaceState(state: Object)

替换 store 的根状态vuex

相关文章
相关标签/搜索