VUEX

2021-04-28  本文已影响0人  iOS白水

1.状态管理

state 不能直接修改
mutations 只能同步,commit触发
action 可以异步 ,dispatch触发

// 以对象形式分发
store.dispatch({
type: 'incrementAsync',
amount: 10
})

  methods: {
    ...mapMutations([
      'increment', // 将 `this.increment()` 映射为 `this.$store.commit('increment')`

      // `mapMutations` 也支持载荷:
      'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.commit('incrementBy', amount)`
    ]),

  ...mapActions([
      'increment', // 将 `this.increment()` 映射为 `this.$store.dispatch('increment')`

      // `mapActions` 也支持载荷:
      'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.dispatch('incrementBy', amount)`
    ]),

}
~~~
上一篇 下一篇

猜你喜欢

热点阅读