mapGetters 辅助函数

1: mapGetters: 辅助函数

      mapGetters:  辅助函数    mapGetters: 辅助函数仅仅将store 中的 getter 映射到局部计算属性:

1: import { mapGetters } from 'vuex'

2: export default {

   computer: {
     // 使用对象展开运算符 将 getter 混入 computer 对象中

     ...mapGetters ([
          'getMachineList'
      ])
   }
 }

2:  Mutation :  更改 Vuex 的store 中状态的唯一方法提交mutation。 

Vuex 中的 mutation 非常类似于事件:每个 mutation 都有一个字符串的 事件类型 (type) 和 一个 回调函数 (handler)。这个回调函数就是我们实际进行状态更改的地方,并且它会接受 state 作为第一个参数

3:   修改store 中数据:

const store = new Vuex.Store({
  state: {
    count: 1
  },
  mutations: {
    increment (state) {
      // 变更状态
      state.count++
    }
  }
})

4: 你不能直接调用一个 mutation handler。

       这个选项更像是事件注册:“当触发一个类型为 increment 的 mutation 时,调用此函数。

       ”要唤醒一个 mutation handler,你需要以相应的 type 调用 store.commit 方法:

store.commit('increment')

5: 提交负荷(payLoad)

   你可以向 store.commit 传入额外的参数,即 mutation 的 载荷(payload)  (Payload:  载荷参数)

// ...
mutations: {
  increment (state, n) {
    state.count += n
  }
}
store.commit('increment', 10)

7: 对象风格提交方式:

    提交 mutation 的另一种方式是直接使用包含 type 属性的对象:

store.commit({
  type: 'increment',
  amount: 10
})

8: 当使用对象风格提交方式的时候: 整个对象都作为载荷传给 mutation 函数; 因此 handle 保持不变。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值